search - ElasticSearch - query documents: All given labels appear at least one time in a nested document -
consider few indexed documents (employees) containing nested documents (skills) 1 property, let's "label", each employee associated few skills. fetch employees (documents) elasticsearch index, master given set of skills, example "python" , "java".
i struggling find suitable query ensure all given skills ("python", "java") appear at least once in set of skills of employee, although do not have appear together!
my mapping similar one:
{ "mappings": { "employee": { "_all": { "enabled": false }, "properties": { "id" : { "type": "integer" }, "first_name" : { "type": "string" }, "last_name" : { "type": "string" }, "skills": { "type": "nested", "properties": { "label": { "type": "string" }, "rating": { "type": "integer" } } } } } } }
so looking solutions (queries) on how retrieve desired results.
you need use two nested
filters combined in bool/filter
query, this:
post /employees/employee/_search { "query": { "bool": { "filter": [ { "nested": { "path": "skills", "query": { "term": { "skills.label": "python" } } } }, { "nested": { "path": "skills", "query": { "term": { "skills.label": "java" } } } } ] } } }
Comments
Post a Comment