Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Search 弹性搜索:匹配不同嵌套对象中的字段_Search - Fatal编程技术网

Search 弹性搜索:匹配不同嵌套对象中的字段

Search 弹性搜索:匹配不同嵌套对象中的字段,search,Search,我是弹性搜索新手,这是我的用户索引: { "user": { "properties": { "branches": { "type": "nested" }, "lists": { "type": "nested" }, "events": { "type": "nested" }, "optOuts": { "type": "nested" } } } } 在这里,分支、事件和列表将包含字段id(int)、countryIso

我是弹性搜索新手,这是我的用户索引:

{
"user": {
"properties": {
  "branches": {
    "type": "nested"
  },
  "lists": {
    "type": "nested"
  },
  "events": {
    "type": "nested"
  },
  "optOuts": {
    "type": "nested"
  }
}
}
}
在这里,分支、事件和列表将包含字段id(int)、countryIso(String)

例如,我需要找到拥有属于countryIso“XX”的电子邮件的用户

{
"query": {
"bool": {
  "must": [
    {
      "exists": {
        "field": "email"
      }
    },
    {
      "match": {
        "prog_id": 3
      }
    },
    {
      "nested": {
        "path": [
          "branches"
        ],
        "query": {
          "query_string": {
            "fields": [
              "branches.countryIso"
            ],
            "query": "AE KW"
          }
        }
      }
    }
  ]
}
}
}
这样,如果他们的分支对象中有那个国家,我就可以得到它们。我想要的是,countryIso存在于分支、列表或事件中。 注意:其中任何一个可能是空的,即分支可能不存在或列表不存在等,或者列表可能不存在

我试过这个:

{
 "query": {
"bool": {
  "must": [
    {
      "exists": {
        "field": "email"
      }
    },
    {
      "match": {
        "prog_id": 3
      }
    },
    {
      "nested": {
        "path": [
          "branches"
        ],
        "query": {
          "query_string": {
            "fields": [
              "branches.countryIso"
            ],
            "query": "AE KW"
          }
        }
      }
    },
    {
      "nested": {
        "path": [
          "lists"
        ],
        "query": {
          "query_string": {
            "fields": [
              "lists.countryIso"
            ],
            "query": "AE KW"
          }
        }
      }
    }
  ]
}
}
}

但两者都不起作用

{
"query": {
"bool": {
  "must": [
    {
      "exists": {
        "field": "email"
      }
    },
    {
      "match": {
        "prog_id": 3
      }
    },
    {
      "nested": {
        "path": [
          "branches",
          "lists"
        ],
        "query": {
          "query_string": {
            "fields": [
              "branches.countryIso",
              "lists.countryIso"
            ],
            "query": "AE KW"
          }
        }
      }
    }
  ]
}
 }
}