首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Elasticsearch结果排序顺序

问Elasticsearch结果排序顺序
EN

Stack Overflow用户
提问于 2019-03-12 15:49:11
回答 1查看 46关注 0票数 1

我想按特定顺序获取结果首先获得精确的短语(match_phrase)匹配,然后匹配短语( match )中的任何单词。例如,如果我搜索"where can I find my account“,我将首先获得包含完整短语"where can I find my account”的文档,然后获取包含"where“、"can”、"find“、"my”、"account“中的一个或多个单词的文档

我的问题是:

代码语言:javascript
复制
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"      }
    } 
    ]
  }

}}

EN

回答 1

Stack Overflow用户

发布于 2019-03-12 20:21:45

您可以使用boost query来提升与match_phrase查询匹配的文档。您可以相应地更改boost参数。

下面的查询应该适用于您

代码语言:javascript
复制
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
                  }
                }
              }
            ]
          }
        }
      ]
    }
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55116459

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档