弹性搜索中同一字段按类型的相关性

Relevance by type on same field in elasticsearch

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

我的基本提升是这样的:

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

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

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

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

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

实现此目的的一种简单方法是 re-writing OP 中的查询作为 dis-max query

弹性搜索示例 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"
                        }
                     }
                  ]
               }
            }
         ]
      }
   }
}