Skip to content Skip to sidebar Skip to footer

Elastic Search Nested Object Query

I have a elastic search index collection like below, '_index':'test', '_type':'abc', '_source':{ 'file_name':'xyz.ex' 'metadata':{ 'format':'.ex'

Solution 1:

This is how I would do it. You need to AND together via bool/filter (or bool/must) two nested queries for each of the condition pair, since you want to match two different nested elements from the same parent document.

{
  "query": {
    "bool": {
      "filter": [
        {
          "nested": {
            "path": "metadata.profile",
            "query": {
              "bool": {
                "filter": [
                  {
                    "term": {
                      "metadata.profile.f1": "a"
                    }
                  },
                  {
                    "term": {
                      "metadata.profile.f2": true
                    }
                  }
                ]
              }
            }
          }
        },
        {
          "nested": {
            "path": "metadata.profile",
            "query": {
              "bool": {
                "filter": [
                  {
                    "term": {
                      "metadata.profile.f1": "b"
                    }
                  },
                  {
                    "term": {
                      "metadata.profile.f2": false
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

Post a Comment for "Elastic Search Nested Object Query"