【问题标题】:Relevance by type on same field in elasticsearchelasticsearch中同一字段的类型相关性
【发布时间】:2017-06-08 07:26:26
【问题描述】:

有什么方法可以boost根据类型在同一字段上搜索结果?

我的基本提升是这样的:

GET _search
{
   "query": {
      "simple_query_string": {
         "query": "mangan",
         "fields":["_all", "title^6"]
      }
   }
}

但对于其他一些文档,我希望标题不那么重要,所以我尝试在它前面加上 type:

GET _search
{
   "query": {
      "simple_query_string": {
         "query": "mangan",
         "fields":[
            "_all",
            "DocumentationPage.title^6",
            "DocumentationPage.title^6"]
      }
   }
}

但是它根本没有提升。作为最后的手段,我可​​以使用Funcsion/Script Score bu 想避免它。

例如,假设文档只包含title 字段。

【问题讨论】:

    标签: elasticsearch full-text-search relevance


    【解决方案1】:

    实现此目的的一种简单方法是将 OP 中的查询重写为 dis-max query

    elasticsearch 5.x 的示例:

     {
       "query": {
          "dis_max": {
             "queries": [
                {
                   "simple_query_string": {
                      "fields": [
                         "_all"
                      ],
                      "query": "mangan"
                   }
                },
                {
                   "bool": {
                      "filter": {
                         "type": {
                            "value": "DocumentationPage"
                         }
                      },
                      "must": [
                         {
                            "simple_query_string": {
                               "fields": [
                                  "title^6"
                               ],
                               "query": "mangan"
                            }
                         }
                      ]
                   }
                }
             ]
          }
       }
    }
    

    【讨论】:

    • 谢谢,按预期工作!似乎这种技术在按不同条件过滤不同类型的文档时也可能会有所帮助。
    猜你喜欢
    • 1970-01-01
    • 2022-01-27
    • 2018-02-01
    • 2021-07-03
    • 2020-04-23
    • 2012-09-07
    • 2011-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多