如何编写查询以在嵌套字段和非嵌套字段中一起查找数据

时间:2019-02-15 21:53:35

标签: elasticsearch elastic-stack

我想找到多个字段搜索。

所以:

GET my_doc/_search
{
  "query": {
    "multi_match" : {
      "query":    "text", 
      "fields": [ "state", "city"] 
    }
  }
}

通常此查询有效,但在嵌套字段中搜索。

但这仅适用于嵌套字段:

GET my_doc*/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "path": "images",
            "score_mode": "max", 
            "query": {
              "bool": {
                "must": [
                  {"match": {"images.description": "Subject" }},
                  {"match": {"images.Number": "10004" }}
                ]
              }
            }
          }
        }
      ]
    }
  }
}

我的问题是:

如何编写查询以搜索无处不在-只需加入我的查询即可在“图片” 位置中查找。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,只是为了加入查询:

 GET my_doc*/_search
    {
      "query": {
        "bool": {
          "must": [
            {
              "multi_match" : {
                "query":    "LAKE", 
                "fields": [ "state", "city"] 
              }
            },

            {
              "nested": {
                "path": "images",
                "score_mode": "max", 
                "query": {
                  "bool": {
                    "must": [
                       {"match": {"images.description": "Subject" }},
                       {"match": {"images.Number": "10004" }}
                    ]
                  }
                }
              }
            }
          ]
        }
      }
    }
相关问题