Querying optional fields in Elasticsearch -


i have es type courses 2 optional fields trainer , trainingcompany in such way in each document have trainer or trainingcompany not both.

i tried query filter courses trainers and/or training companies:

"query": {     "bool": {       "must_not": [         {           "terms": {             "trainingcompany.slug": [               "company-slug"             ]           }         },         {           "terms": {             "trainer.slug": [               "trainer-slug"             ]           }         }       ]     }   } 

but, getting documents in return. thought need exists check if each field exists, still unable figure out.

here sample course if needed:

    {               "title": "title",               "description": "description",               "slug": "slug",               "duration": 10,               "language": "en",               "price": 1500,               "trainingcompany": {                 "name": "the bridge",                 "slug": "the-bridge",             } } {           "title": "title",           "description": "description",           "slug": "slug",           "duration": 1,           "language": "fr",           "price": 500,           "trainer": {             "firstname": "jemli",             "lastname": "fathi",             "slug": "jemli-fathi",             "photo": "url"           }         } 

according mapping, should use keyword sub-fields this:

"query": {     "bool": {       "must_not": [         {           "terms": {             "trainingcompany.slug.keyword": [               "company-slug"             ]           }         },         {           "terms": {             "trainer.slug.keyword": [               "trainer-slug"             ]           }         }       ]     }   } 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -