复合键的弹性搜索查询,如SQL [英] Elastic search query for composite keys like in SQL
本文介绍了复合键的弹性搜索查询,如SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下情况:
假设我有一个关系表:
I have below scenario: Suppose I have a relational table :
Key1 Key2 Key3 Value
A x v1 0
A x v1 10
B x v1 5
A y v2 7
A y v2 2
这里我有(Key1,Key2,Key3)的逻辑键组合。现在我需要具有最大值的记录。所以我期望下面的结果对应于不同的逻辑键:
Here I have logical key composite of (Key1, Key2, Key3). Now I need records with the maximum value. So I expect below result corresponding to different logical keys:
Key1 Key2 Key3 Value
A x v1 10
B x v1 5
A y v2 7
现在我想为它写一个弹性搜索查询。有人可以给我一些想法吗?
Now I want to write an Elastic Search query for it. Can somebody give me some idea about it ?
推荐答案
然后你可以用多层次的术语
这样的聚合:
Then you can go with a multi-level terms
aggregation like this:
{
"size": 0,
"aggs": {
"key1": {
"terms": {
"field": "key1"
},
"aggs": {
"key2": {
"terms": {
"field": "key2"
},
"aggs": {
"key3": {
"terms": {
"field": "key3"
},
"aggs": {
"doc": {
"top_hits": {
"sort": {"value": "desc"}
}
}
}
}
}
}
}
}
}
}
这篇关于复合键的弹性搜索查询,如SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文