How to check if a the particular element of an array field exists in elasticsearch? -
this sample document index
{ "name": "sandy", "age": "25", "ug":["b.tech"], "pg":["ms","phd"] } i want filter candidates on basis of pg qualifications. want 2 types of filters.
in cases pg field empty. so,i need filter out ones have pg qualifications.
i want candidates pg qualification "ms". not others "mba" , all. given first element under "pg" array. how can implement in elasticsearch?
considering information provided, suggest follows.
for first question, try using exists filter filtering records containing atleast 1 pg value in array.
{ "query": { "constant_score": { "exists": { "field": "pg" } } } }
for second question, considering fact result can contain other elements along ms in array shown below.
{ "query": { "bool": { "must": [ { "term": { "additionalskill": "java" } }, { "constant_score": { "filter": { "exists": { "field": "additionalskill" } } } } ] } } }
if use case dint allow other elements other ms in array have limit result records using scripting feature in elasticsearch.
Comments
Post a Comment