如何在任何嵌套字段中搜索值?

问题描述

基本上,我必须在文档的所有字段中找到匹配的值。

我尝试使用查询字符串,但不幸的是,它仅在第一级字段中搜索。嵌套字段值未使用查询字符串获取,或者可能是我使用的方式错误

我尝试过

GET events/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "default_field": "*","query": "match"
          }
        }
      ]
    }
  }
}

我将如何查询它来检查包括嵌套字段在内的所有字段。

预先感谢

解决方法

您始终可以有多个子句,一个子句用于一级字段,另一个子句用于在OR条件中组合的嵌套字段:

GET events/_search
{
  "query": {
    "bool": {
      "minimum_should_match": 1,"should": [
        {
          "query_string": {
            "default_field": "*","query": "match","lenient": true
          }
        },{
          "nested": {
            "path": "nested_field","query": {
              "query_string": {
                "default_field": "nested_field.*","lenient": true
              }
            }
          }
        }
      ]
    }
  }
}