elasticsearch中的相同类型的相关性 [英] Relevance by type on same field in elasticsearch

查看:232
本文介绍了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 ]
}
}
}

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

为了举例,假设文档只包含 title 字段。

实现这一点的一种简单方法是重写查询在OP中作为 dis -max查询



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中的相同类型的相关性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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