I指數這些:Elasticsearch - 使用條款鬥鍵作爲過濾變量
POST nephi/boat/1
{
"plates": {
"id": 123,
"type": "brass"
},
"compass": {
"id": 123,
"name": "liahona"
}
}
POST nephi/boat/2
{
"plates": {
"id": 100,
"type": "brass"
},
"compass": {
"id": 234,
"name": "liahona"
}
}
我用這個搜索查詢,所以我可以做一個彙總,其中plates.id
和compass.id
是相等的:
POST nephi/boat/_search
{
"aggs": {
"terms_agg": {
"terms": {
"field": "plates.id"
},
"aggs": {
"filter_agg": {
"filter": {
"term": {
"compass.id": 123
}
}
}
}
}
},
"size": 0
}
而不是使用"compass:id": 123
,我希望能夠使用變量代替123,如"compass:id": "__bucket_key"
,其中__bucket_key
將在上面的第一個文檔中引用123,並在上面的第二個文檔中引用100(plates.id
s)。
是這樣的可能嗎?
你想聚集在plates.id其中'plates.id == compass.id' ?? – Richa
@Richa,是的。在這個例子中看起來似乎很愚蠢,但我想這樣做,所以我可以做另一個度量子聚合(比如count或sum),只能在'''plates.id == compass.id''' 。 – chevin99