gpt4 book ai didi

search - 带有过滤器的elasticsearch中的多词查询

转载 作者:行者123 更新时间:2023-12-03 01:47:23 24 4
gpt4 key购买 nike

我通过以下字段将数据集放入ES:

Category,Question,Answer

尝试在“问题”字段或“答案”字段中查询词组“世界系列”的elasticsearch索引,但也必须仅将其结果/搜索限制为我指定的类别
{
"query" : {
"constant_score" : {
"filter" : {
"bool" : {
"should" : [
{ "term" : {"Question" : "world series"}},
{ "term" : {"Answer" : "world series"}}
],
"must" : {
"term" : {"Category" : "Sport"}
}
}
}
}
}
}'

但是,当我这样做时,它不允许我使用多个单词(即“世界大赛”)。

如何搜索词组/术语,但仅搜索所需的类别(即运动)?

最佳答案

试试这个

{
"query": {
"bool": {
"must": [
{
"match": {
"Category": "Sport"
}
},
{
"multi_match": {
"query": "world series",
"type": "cross_fields",
"operator": "and",
"fields": [
"Question",
"Answer"
]
}
}
],
"must_not": [],
"should": []
}
},
"from": 0,
"size": 10,
"sort": [],
"aggs": {}
}

关于search - 带有过滤器的elasticsearch中的多词查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42834769/

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