Query for specific pair of fields in Elastic

Hello,
I have two documents:

POST query_test/_doc
{
  "field": [
    {
      "field1": "Pam",
      "field2": "Beesly"
    },
    {
      "field1": "Jim",
      "field2": "Halpert"
    }
  ]
}

POST query_test/_doc
{
  "field": [
    {
      "field1": "Pam",
      "field2": "Halpert"
    },
    {
      "field1": "Jim",
      "field2": "Halpert"
    }
  ]
}

How to query that index, to return only second document with Pam Halpert?
Below query returns both documents:

GET query_test/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "field.field1": "Pam"
          }
        },
        {
          "match": {
            "field.field2": "Halpert"
          }
        }
      ]
    }
  }
}

Have a look at nested documents.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.