Querying nested arrays

My current data representation is as follows:

{
  ...
  "_source": {
      "thing1": {
          "data": [[1,2,3], [4,5,6], [7,8,9]]
      },
      "thing2": {
          "data": [[1,2,3], [4,5,6], [7,8,9]]
      }
  }
}

Where I have a bunch of nested arrays. I want to be able to query to see if an element exists within a row. So for example, I'd want to see if 1 was in the first nested list of the thing_1. I'm not sure how to do this from reading the nested documentation, since those examples focus on nested objects.

How do I specify my mapping, and what do I need to do to make queries?

Thanks in advance!

Based on the bullet points on this doc page, ES doesn't index the data as you'd hope it would. I think it would end up just as [1,2,3,4,5,6,7,8,9].

I think - I could be wrong.

But perhaps you could query via a script to inspect the doc values?

Thank you so much for responding to this.

I ended up getting this to work with a script that looked like this:

GET _search
{
  "query": {
    "bool":{
      "must": {
        "match_all": {}
      },
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "a": "3"
              }
            }
          ]
        }
      }
    }
  }
}

Now, hoping to figure out if I can tell where in the doc my match was, since not all my documents are structured the same, making it seem like highlights aren't well suited for what I'm trying to do. Do you think I could do something with scripts?

I think the community needs to understand the problem a bit better - can you provide more detail? Actual sample documents, your index settings/document mappings.

But consider if you can restructure your data to denormalize it - ie. get rid of the array of arrays, in favour of duplicating some data. That usually makes things easier - but as always, it depends on how you need to query the data.

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