gpt4 book ai didi

elasticsearch - Elasticsearch多个查询有限制

转载 作者:行者123 更新时间:2023-12-03 02:04:42 24 4
gpt4 key购买 nike

我正在尝试编写一个Elasticsearch查询,其中我在标题和描述中匹配多个单词。下面的代码可以正常工作,但是提供了所有与这些单词匹配的文章。我的目标是每个查询字词需要4篇文章,例如蒂姆·库克的4个结果和史蒂夫·乔布斯的四篇文章

{
"query": {
"multi_match": {
"query": ["Tim Cook","Steve Jobs"],
"fields": ["Title", "Description" ],
"operator":"AND"
}
}
}

最佳答案

Top hits aggregations是您的寻找-
基本上给2个filter aggregation,然后在它们旁边嵌套热门匹配。

所以下面的东西应该可以正常工作

{
"size": 0,
"query": {
"multi_match": {
"query": [
"Tim Cook",
"Steve Jobs"
],
"fields": [
"Title",
"Description"
],
"operator": "AND"
}
},
"aggs": {
"tim": {
"aggs": {
"top_hits": {}
},
"filter": {
"query": {
"multi_match": {
"query": [
"Tim Cook"
],
"fields": [
"Title",
"Description"
],
"operator": "AND"
}
}
}
},
"steve": {
"aggs": {
"top_hits": {}
},
"filter": {
"query": {
"multi_match": {
"query": [
"Steve Jobs"
],
"fields": [
"Title",
"Description"
],
"operator": "AND"
}
}
}
}
}
}

关于elasticsearch - Elasticsearch多个查询有限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28026832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com