我有以下 JSON 结构,我想在 ElasticSearch 中运行聚合查询:
{
"user_id": 1,
"gender_id": 1,
"locale_id": 6,
"age": 38,
"hometown_city_id": 1002,
"current_city_id": 672,
"books": [
{
"b_id": 2065,
"b_name": "aut qui assumenda ut",
"b_cat": 56
},
{
"b_id": 2527,
"b_name": "libero et laudantium",
"b_cat": 132
},
...
]
}
我基本上想要做的是例如显示用户阅读的前 5 本书 "gender_id": "1"(male) 也阅读了 "b_id": 2065 的书。
作为 ElasticSearch 的初学者,我还没有找到解决方案。我知道 v1.0 附带了聚合模块 (https://github.com/elasticsearch/elasticsearch/issues/3300),但我无法让它运行。
如果有人已经实现了类似的东西,请帮忙!提前非常感谢!
最佳答案
也许是这样的(不确定嵌套的books.field):
{
"query" : {
"match_all" : { }
},
"facets" : {
"filter_one" : {
"filter" : {
"and" : [
{"filter" : {"term" : { "gender_id" : 1 }},
{"filter" : {"term" : { "books.b_id" : 2065 }},
]
}
},
"book_cnt" : {
"terms" : {
"field" : "books.b_name",
"size" : 5
}
}
}
}
关于ElasticSearch 聚合查询可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20640278/