我是在彈性搜索中對指標名稱建立索引。度量名稱的格式爲foo.bar.baz.aux
。這是我使用的索引。術語聚合(實現分層刻面)查詢性能緩慢
{
"index": {
"analysis": {
"analyzer": {
"prefix-test-analyzer": {
"filter": "dotted",
"tokenizer": "prefix-test-tokenizer",
"type": "custom"
}
},
"filter": {
"dotted": {
"patterns": [
"([^.]+)"
],
"type": "pattern_capture"
}
},
"tokenizer": {
"prefix-test-tokenizer": {
"delimiter": ".",
"type": "path_hierarchy"
}
}
}
}
}
{
"metrics": {
"_routing": {
"required": true
},
"properties": {
"tenantId": {
"type": "string",
"index": "not_analyzed"
},
"unit": {
"type": "string",
"index": "not_analyzed"
},
"metric_name": {
"index_analyzer": "prefix-test-analyzer",
"search_analyzer": "keyword",
"type": "string"
}
}
}
}
上述指標的度量標準名稱創建下列條款foo.bar.baz
foo
bar
baz
foo.bar
foo.bar.baz
如果我有一堆指標,像下面
a.b.c.d.e
a.b.c.d
a.b.m.n
x.y.z
我要編寫一個查詢搶令牌的第n級。在上面的例子中
for level = 0, I should get [a, x]
for level = 1, with 'a' as first token I should get [b]
with 'x' as first token I should get [y]
for level = 2, with 'a.b' as first token I should get [c, m]
我想不出任何其他方式,除了寫術語聚合。要找出a.b
的二級令牌,下面是我提出的查詢。
time curl -XGET http://localhost:9200/metrics_alias/metrics/_search\?pretty\&routing\=12345 -d '{
"size": 0,
"query": {
"term": {
"tenantId": "12345"
}
},
"aggs": {
"metric_name_tokens": {
"terms": {
"field" : "metric_name",
"include": "a[.]b[.][^.]*",
"execution_hint": "map",
"size": 0
}
}
}
}'
這會導致下面的問題。我解析輸出並從那裏抓取[c,m]。
"buckets" : [ {
"key" : "a.b.c",
"doc_count" : 2
}, {
"key" : "a.b.m",
"doc_count" : 1
} ]
到目前爲止好。該查詢適用於大多數租戶(請注意上面的tenantId
term
查詢)。對於有大量數據(大約1Million)的某些租戶來說,表現確實很慢。我猜測聚合的所有術語都需要時間。
我想知道術語聚合是否是這種數據的正確選擇,並且還在尋找其他可能的查詢類型。
我不清楚你需要什麼。你需要計數嗎?或者你需要c和m嗎?或者您是否需要包含以下文件:a.b.c.d.e - a.b.c.d - a.b.m.n? –
我只需要c和m。 – Chandra
@JettroCoenradie我只需要c和m。基本上什麼是給定前綴的下一級可能令牌。 – Chandra