Querying on multiple flattened sub-fields for an array of items

If I have a flattened or object field named X, which is an array of objects with subfields A and B, how can I query for an item that has specific values for both A and B?

E.g. if I run the following:

{
   "query": {
      "bool": {
         "must": [
            {
               "term": {
                  "X.A": "v1"
               }
            },
            {
               "term": {
                  "X.B": "v2"
               }
            }
         ]
      }
   }
}

It'll include hits like the following hit which I don't want:

{"x": [
   {
      "A": "v1",
      "B": "v0",
   },
   {
      "A": "v0",
      "B": "v2",
   }
]}

I only want hits like:

{"X": [
   {
      "A": "v1",
      "B": "v2"
   }
]}

Objects in array has no meaning otherwise it is in a nsted field. It seems you have to use nested field type to get the desired result.

Thats too bad. Nested fields blow up the document count as they create a document for every sub-object

I wonder why they can't order the internal arrays used per subfield to be in sync with the order of objects in the array

In my guess, one of the possible reason is that the internal structure for index of multi-value field is not array.

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