Exact match on dynamic object field

I have a field with a dynamic mapping:

"properties": {
  "tags": {
    "type": "object",
    "dynamic": "true"
  }
}

Now I want to find the documents that have tags.color = "red" and tags.species = "herring" but no other tags.

This query finds such documents:

{
  "query": {
    "bool": {
      "filter": [
        { "term": { "tags.color": "red" } },
        { "term": { "tags.species": "herring" } }
      ]
    }
  }
}

Unfortunately it also finds documents with more than those two tags. How can I remove those from the result?

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