Querying a nested field in elasticsearch


(Sandhya Rathinapandian) #1

I have a nested field in the index and i am having issues with querying it.

Suppose i have the below json in my index:
{car:[{name: abc, color:red},{name:xyz, color:blue}]}
{car:[{name: abc1, color:red},{name:xyz1, color:black}]}

I am trying to search for all the red color cars:

{ "query": { "nested" : { "path" : "car", "score_mode" : "avg","query" : { "bool" : { "must" : [ { "match" : {"car.color" : "red"} } ]} } } }}'

I am getting all the four cars.

Kindly help us on querying this.

Thanks


(system) #2