弹性搜索 - 按文档类型排序 [英] Elastic Search - Sort By Doc Type

查看:131
本文介绍了弹性搜索 - 按文档类型排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有两种不同文档类型的弹性搜索索引:'a''b'。我想按类型排序我的结果,并优先选择 type ='b'(即使它的得分较低)。我在客户端一直在搜索下面的搜索结果并对它们进行排序,但是我意识到这种方法不能正常工作,因为我只检查前10个结果,这些结果通常不包含任何b。增加回报结果并不理想。我想要弹性搜索来完成这项工作。

I have an elastic search index with 2 different doc types: 'a' and 'b'. I would like to sort my results by type and give preference to type='b' (even if it has a low score). I had been consuming the results of the search below at the client end and sorting them but I've realized that this approach does not work well since I am only inspecting the first 10 results which often does not contain any b's. Increasing the return results is not ideal. I'd like to get the elastic search to do the work.

http://< server>:9200 / my_index / _search? q = london

推荐答案

你需要玩 function_score ,并且取决于您如何评分文档,测试一些重量值, boost_mode s和 score_mode s 。例如:

You would need to play with function_score and, depending on how you already score your documents, test some weight values, boost_modes and score_modes for each type. For example:

GET /some_index/a,b/_search
{
  "query": {
    "function_score": {
      "query": {
        # your query here
      },
      "functions": [
        {
          "filter": {
            "type": {
              "value": "b"
            }
          },
          "weight": 3
        },
        {
          "filter": {
            "type": {
              "value": "a"
            }
          },
          "weight": 1
        }
      ],
      "score_mode": "first",
      "boost_mode": "multiply"
    }
  }
}

这篇关于弹性搜索 - 按文档类型排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆