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.

  1. in cases pg field empty. so,i need filter out ones have pg qualifications.

  2. 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.

  1. for first question, try using exists filter filtering records containing atleast 1 pg value in array.

    { "query": { "constant_score": { "exists": { "field": "pg" } } } }

  2. 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" } } } } ] } } }

  3. if use case dint allow other elements other ms in array have limit result records using scripting feature in elasticsearch.


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -