我想按特定顺序获取结果首先获得精确的短语(match_phrase)匹配,然后匹配短语( match )中的任何单词。例如,如果我搜索"where can I find my account“,我将首先获得包含完整短语"where can I find my account”的文档,然后获取包含"where“、"can”、"find“、"my”、"account“中的一个或多个单词的文档
我的问题是:
GET my_index/_search
{
"query": {
"bool": {
"should": [
{
"match": {"body": "right usage of Localization" }
} ,
{
"match": {"title": "right usage of Localization" }
}
],
"should": [
{
"match_phrase": {"body": "translated" }
},
{
"match_phrase": {"title": "translated" }
}
]
}}}
发布于 2019-03-12 20:21:45
您可以使用boost query来提升与match_phrase查询匹配的文档。您可以相应地更改boost参数。
下面的查询应该适用于您
POST phrase_index/_search
{
"query": {
"bool": {
"should": [
{
"bool": {
"should": [
{
"match": {
"title": "this is where it should work first"
}
},
{
"match": {
"body": "this is where it should work first"
}
}
]
}
},
{
"bool": {
"should": [
{
"match_phrase": {
"title": {
"query": "this is where it should work first",
"boost": 20
}
}
},
{
"match_phrase": {
"body": {
"query": "this is where it should work first",
"boost": 20
}
}
}
]
}
}
]
}
}
}https://stackoverflow.com/questions/55116459
复制相似问题