Sunday, 15 April 2012

ElasticSearch : Query multiple value in array -



ElasticSearch : Query multiple value in array -

i trying set query/filter elastic search. here construction like

{ _id:"0872300234", customers:[ { name:"bob", priority:1, type:"gooduser" }, { name:"dan", priority:10, type:"baduser" }, { name:"sam", priority:10, type:"gooduser" }, { name:"cam", priority:2, type:"baduser" } ] }

so lets phone call "profile" document/record. find profiles has client in has priority of 10 , "gooduser" (the same customer) in illustration sam match dan not. got query gives me profile client has priority 10 , customer(not same one) has type gooduser.

is there way query array item whole.

thanks

you need nested types that. more nested objects can find here , reason why need them in situations associations between nested fields important. in case, mapping need this:

{ "mappings": { "profile": { "properties": { "customers": { "type": "nested", "properties": { "name": { "type": "string" }, "priority": { "type": "integer" }, "type": { "type": "string" } } } } } } }

and query need nested, well:

{ "query": { "nested": { "path": "customers", "query": { "bool": { "must": [ {"match": { "customers.type": "gooduser" }}, {"term": { "customers.priority": { "value": 10 } }} ] } } } } }

elasticsearch

No comments:

Post a Comment