Conditional query in ElasticSearch? -


i'm relatively new elasticsearch , need advice. after several tries, did not found solution , that's why need you.

i want make conditional query based on document content.

let me explain, have documents in es:

{    "name": "product n°1",    "type": "mail",    "sub": "letter" }, {    "name": "product n°2",    "type": "video",    "sub": null }, {    "name": "product n°3",    "type": "mail",    "sub": "postcard" } 

the user can filter types , sub checkboxes (so, user can search more 1 type , sub @ same time)

edited

customers can selects checkbox types of products want es (for ex: video, image, mail), can select of them.

the "document" type has 4 sub-types: letter, postal card, paper, printed , can select sub type want retrieve too.

so, admit customer selected video , mail, , letter sub-type of mail.

i want es returns of documents within selected types , letters when document "mail" type.

sorry mistakes, i'm new es.

thanks of trying !


update 2

here's query andrei stefan's solution

{   "query": {     "filtered": {       "query": {         "match_all": []       },       "filter": {         "bool": {           "should": [             {               "terms": {                 "type": [                   "video",                   "mail"                 ]               }             },             {               "bool": {                 "must": [                   {                     "term": {                       "type": mail                     }                   },                   {                     "terms": {                       "sub": [                         "letters"                       ]                     }                   }                 ]               }             }           ]         }       }     }   } } 

es returns of documents of type video , mail, not apply fillter letters when type mail.

a thousand tanks @andrei stefan. difference between update 2 had delete "mail" first "should" query.

{   "query": {     "filtered": {       "query": {         "match_all": []       },       "filter": {         "bool": {           "should": [             {               "terms": {                 "type": [                   "video"                 ]               }             },             {               "bool": {                 "must": [                   {                     "term": {                       "type": mail                     }                   },                   {                     "terms": {                       "sub": [                         "letters"                       ]                     }                   }                 ]               }             }           ]         }       }     }   } } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -