select matching objects from array in elasticsearch -
{ class: 1, users: [{ name: 'abc', surname: 'def' }, { name: 'xyz', surname: 'wef' }, { name: 'abc', surname: 'pqr' }] }
i have document structure above object , want return users have name 'abc' problem matches name 'abc' returns array. want matched users .
mapping -
{ "class":"string", "users" : { "type" : "nested", "properties": { "name" : {"type": "string" }, "surname" : {"type": "string" } } } }
then if have users
field mapped nested
type, it's start!
using nested inner_hits
, can retrieve matching user names query one:
{ "_source": false, "query": { "nested": { "path": "users", "inner_hits": { <---- magic happens "_source": [ "name" ] }, "query": { "bool": { "must": [ { "term": { "users.name": "abc" } } ] } } } } }
Comments
Post a Comment