本文介绍了elasticsearch中的相同类型的相关性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法可以根据类型在同一个字段上添加 boost 搜索结果?

我的基本提示是例如:

  GET _search 
{
query:{
simple_query_string :{
query:mangan,
fields:[_ all,title ^ 6]
}
}
}

但是对于其他一些文档,我希望title不那么重要,所以我试着用类型前缀:

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

但它不会提升。作为最后的手段,我可​​以使用。



elasticsearch 5.x示例:

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

query:mangan
}
}
]
}
}
]
}
}
}


Is there any way to boost search results on same field depending on type?

My basic boosting is something like:

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

But for some other documents I want title to be less important, so I tried to prefix it with type:

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

But then it does not boost at all. As a last resort I could use Funcsion/Script Score bu would like to avoid it.

For sake of example, assume that document contains just title field.

解决方案

A simple way to achieve this is re-writing the query in the OP as a dis-max query.

Example for 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"
                        }
                     }
                  ]
               }
            }
         ]
      }
   }
}

这篇关于elasticsearch中的相同类型的相关性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 03:23