在弹性搜索中进行索引时, [英] _score while doing indexing in elasticsearch

查看:95
本文介绍了在弹性搜索中进行索引时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

{
  "query": {
    "custom_score": {
      "query": {
        "match": {
          "xxx": {
            "query": "foobar"
          }
        }
      },
      "filter": {
        "and": [
          {
            "query": {
              "match": {
                "yyyy": {
                  "query": "barfoo"
                }
              }
            }
          }
        ]
      }
    },
    "script": "_score * doc['_score']"
  }
}

这给错误

 [custom_score] query does not support [filter]

然后如何评估这样的查询?

Then how to evaluate such query?

推荐答案

我建议你看看你对提升的要求,因为你目前的脚本没有什么意义。

I would suggest you to look at your requirements regarding boosting, since your current script doesn't make much sense.

另外,请查看弹性搜索的文档查询DSL 。它提供复合查询和简单查询,可以组合在一起。如错误所示,您不能将过滤器放在自定义分数查询中。您可以在自定义分数查询内使用过滤查询 :$ {


Also, have a look at the documentation for the elasticsearch query DSL. It provides either compound queries and simple ones, which you can combine together. As the error says, you can't put a filter inside a custom score query. You can either use a filtered query inside the custom score query:

{
  "query": {
    "custom_score": {
      "query": {
        "filtered" : {
          "query" : {
            "match": {
              "xxx": {
                "query": "foobar"
              }
            }
          },
          "filter" : {
            "and": [
              {
                "query": {
                  "match": {
                    "yyyy": {
                      "query": "barfoo"
                    }
                  }
                }
              }
            ]
          }
        }
      },
      "script": "_score * doc['_score']"
    }
  }
}

或使用顶级过滤器,如下所示:

or use a top level filter like this:

{
  "query": {
    "custom_score": {
      "query": {
        "match": {
          "xxx": {
            "query": "foobar"
          }
        }
      },
      "script": "_score * doc['_score']"
    }
  },
  "filter": {
    "and": [
      {
        "query": {
          "match": {
            "yyyy": {
              "query": "barfoo"
            }
          }
        }
      }
    ]
  }
}

两个选项之间的区别是,如果您制作了顶层过滤器,则不考虑顶级过滤器您的搜索请求中的方面也是如此,而如果您将过滤器放在查询中,则会被考虑。

The difference between the two options is that the top level filter is not considered if you make facets too in your search request, while if you put the filters within the query they are considered.

另外需要注意的事项:您不需要过滤器如果你只有一个子句。而且,过滤器中的全文搜索通常是没有意义的,因为过滤器是可缓存的,并且由于全文搜索是免费的,并且几乎不可预测,因此缓存它们将是浪费的。

One other thing to look at: you don't need an and filter if you have only a single clause. Also, it usually doesn't make sense to put a full-text search within a filter, since filters are cacheable and given that full-text searches are free and pretty much unpredictable it would be a waste to cache them.

这篇关于在弹性搜索中进行索引时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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