带过滤器的elasticsearch中的多词查询
我使用以下字段将数据集放入ES中:带过滤器的elasticsearch中的多词查询,search,elasticsearch,filter,Search,elasticsearch,Filter,我使用以下字段将数据集放入ES中: Category,Question,Answer 尝试在“问题”字段或“答案”字段中查询短语世界系列的elasticsearch索引,但其结果/搜索必须仅限于我指定的类别 { "query" : { "constant_score" : { "filter" : { "bool" : { "should" : [ { "term" :
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": {}
}
您可以添加一个名为Searchtext的额外字段,该字段将被分析,Searchtext可能包括类别、问题、答案 然后,
{
"query": {
"constant_score": {
"filter": {
"bool": {
"must": {
"term": {
"Category": "Sport"
},
"match": {
"SearchText": {
"query": "world series",
"operator": "and"
}
}
}
}
}
}
}