How to query elements in an array


#1

Json below (only _source part is shown) is for example purpose only is shows an document from a fictional real estate broker

Question: how do i query this document if it has lots with ownerId: "Jim Anderson"

{
.
.
.
  "_source": {
    "city": {
      "district10": [
       { "landlot1": {
          "price": 50,
          "size": 5,
          "ownerId": "Jim Anderson"
        }
      },
        {
          "landlot2": {
            "price": 45,
            "size": 9,
            "ownerId": "Anna Simson"
          }
        }
      ]
    }
  }
}

I tried something like this but didnt work

{
 
  "query": {
    "match": {
      "city.district10.landlot1.ownerId" : "Jim Anderson"
    }
  }
}

How to make this work?


(Ryan Ernst) #2

You'll need to use nested docs in order to be able to distinguish array elements from each other.


#3

thanks