在ElasticSearch 7+中,如何搜索所有文本字段? [英] In ElasticSearch 7+ how do you search all text fields?

查看:110
本文介绍了在ElasticSearch 7+中,如何搜索所有文本字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我存储在Elasticsearch 7.3中的文档中搜索一个单词

I want to search for a word in documents I have stored in Elasticsearch 7.3

我希望在以前版本的Elasticsearch上工作的示例如下:

An example of what I would like on previous versions of Elasticsearch that worked is:

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "_all": "oliver"
          }
        }
      ],
      "must_not": [],
      "should": []
    }
  },
  "from": 0,
  "size": 10,
  "sort": [],
  "aggs": {}
}

但是该查询不适用于Elasticsearch 7+,因为 _all 已被删除。既然 _all 字段消失了,我该如何编写查询以完成相同的事情?

But this query will not work on Elasticsearch 7+ because _all has been removed. How can I write the query to accomplish the same thing now that the _all field is gone?

注意:阅读了使用 copy_to 将所有字段复制到自定义字段中的建议,但这需要显式地写出每个字段以包括在all_fields字段中。由于我有很多小字段,因此我试图避免这种情况,而是复制能够查询_all允许的行为。

Note: I've read the suggestions to use copy_to to copy all fields into a custom field but that requires explicitly writing out each field to include in the all_fields field. Since I have lots of little fields I am trying to avoid this and instead replicate the behavior that being able to query _all allowed.

推荐答案

在ES文档中提到过。


_all可能不再为6.0+版本中创建的索引启用,请使用自定义字段和映射copy_to参数

_all may no longer be enabled for indices created in 6.0+, use a custom field and the mapping copy_to parameter

因此,您需要做的是创建自己的自定义 _all 字段,您可以将其命名为 all_fields 等,然后使用 copy_to 将所有字段值复制到您自己的 all_fields 中,因此,由于此自定义字段具有所有字段值,因此您可以使用它代替 _all 字段。

So, what you need to do is create your own custom _all field, which you can name like all_fields etc and then use copy_to to copy all fields value in your own all_fields, so now as this custom field has all the fields value, so you can use it instead of _all fields.

这篇关于在ElasticSearch 7+中,如何搜索所有文本字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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