json - Elasticsearch | filter on not related nested data -


ok, today have problem filter elasticsearch query double nested not related fields specs.value.text , specs.spec.text.

the mapping of these fields:

... "specs": { "type": "nested", "properties": { "spec": {   "type": "nested",   "properties": {     "text": {       "type": "string",       "fields": {         "raw": {           "type": "string",           "index": "not_analyzed"         }       }     }   } },  "value": { "type": "nested", "properties": {   "text": {     "type": "string",     "fields": {       "raw": {         "type": "string",         "index": "not_analyzed"         }       }     }     }   } } } .... 

the question when want filter query request:

    {       "query": {         "filtered": {           "filter": {             "and": {               "filters": [                 {                   "nested": {                     "filter": {                       "nested": {                         "filter": {                           "match": {                             "specs.value.text": "10"                           }                         },                         "path": "specs.value"                       }                     },                     "path": "specs"                   }                 },                 {                   "nested": {                     "filter": {                       "nested": {                         "filter": {                           "match": {                             "specs.spec.text": "délai de livraison"                           }                         },                         "path": "specs.spec"                       }                     },                     "path": "specs"                   }                 }               ]             }           },           "query": {             "match_all": {}           }         }       },       "_source": [         "specs"       ]     } 

elasticsearch return document contains word délai de livraison in specs.spec.text or 10 in specs.value.text

exemple of result: first object:

  ...   "specs": [       {         "value": [           {             "text": "10",             "lang": "fr-fr"           }         ],         "spec": [           {             "text": "délai de livraison",             "lang": "fr-fr"           }         ]       },         {          "value": [           {             "text": "10",             "lang": "fr-fr"           }         ],         "spec": [           {             "text": "volume",             "lang": "fr-fr"           }         ]       }   ]   ... 

the second object:

    ...     "specs": [       {         "value": [           {             "text": "7"           }         ]         "spec": [           {             "text": "délai de livraison"           }         ]       }     ]     ... 

the correct query should following

{     "query": {         "bool": {             "must": [{                 "nested": {                     "path": "specs",                     "query": {                         "bool": {                             "must": [{                                 "nested": {                                     "path": "specs.value",                                     "query": {                                         "bool": {                                             "must": [{                                                 "match": {                                                     "specs.value.text": "10"                                                 }                                             }]                                         }                                     }                                 }                             }, {                                 "nested": {                                     "path": "specs.spec",                                     "query": {                                         "bool": {                                             "must": [{                                                  "match": {                                                     "specs.spec.text": "délai de livraison"                                                  }                                             }]                                         }                                     }                                 }                             }]                         }                     }                 }             }]         }     } } 

since running 2 nested queries @ specs level, both documents match both documents match each filter in different nested documents under specs. scope , conditions same nested document fire filters under 1 nested query

hope helps ajay


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -