我想编写一个弹性查询,该查询应返回Sidney Sheldon和John Gresham等2位作者的前三本书。
文档包含字段ID,标题,作者,no_copies_sold,release_Date ...
我想在一次查询中完成此操作,而不是对Sidney Sheldon和John Gresham分别查询两次。
非常感谢您的帮助。
我想编写一个弹性查询,该查询应返回Sidney Sheldon和John Gresham等2位作者的前三本书。
文档包含字段ID,标题,作者,no_copies_sold,release_Date ...
我想在一次查询中完成此操作,而不是对Sidney Sheldon和John Gresham分别查询两次。
非常感谢您的帮助。
首先对作者进行过滤,以仅定位所需的文档。 按作者汇总后,再获取前3个no_copies_sold(= top_book)并询问标题(如果需要,在查询中添加其他字段)。
{
"size": 0,"query": {
"terms": {
"author": [
"Sidney Sheldon","John Gresham"
]
}
},"aggs": {
"author_agg": {
"terms": {
"field": "author"
},"aggs": {
"hits": {
"top_hits": {
"sort": [
{
"no_copies_sold": {
"order": "desc"
}
}
],"_source": [
"title"
],"size": 3
}
}
}
}
}
}