elasticsearch - How to filter by ids together with filter fields value? -


how add additional filter match category values in blog.post.notes fields? first want filter ids, filter notes category, possible?

i can filter ids:

get posts/posts/_search?fields=_id&_source=blog.post.notes {   "query": {     "filtered": {       "query": {         "match_all": {}       },       "filter": {         "ids": {           "values": [             "100000000001234"           ]         }       }     }   } } 

how filter e.g. "test" category current results:

{   "took": 58,   "timed_out": false,   "_shards": {     "total": 5,     "successful": 5,     "failed": 0   },   "hits": {     "total": 1,     "max_score": 1,     "hits": [{       "_index": "posts",       "_type": "posts",       "_id": "100000000001234",       "_score": 1,       "_source": {         "blog": {           "post": {             "notes": {               "main": [{                 "message": "blablabla",                 "category": "test"               }, {                 "message": "blablabla",                 "category": "other"               }],               "cart": [{                 "message": "blablabla",                 "category": "test"               }, {                 "message": "blablabla",                 "category": "other"               }]             }           }         }       }     }]   } } 

curl -xget localhost:9200/posts/_mapping/posts

{   "posts": {     "mappings": {       "posts": {         "dynamic_templates": [{           "blog": {             "mapping": {               "index": "analyzed"             },             "path_match": "blog.*",             "path_unmatch": "*.medias.*"           }         }, {           "ids": {             "mapping": {               "index": "not_analyzed",               "type": "string"             },             "match": "_id|base_id",             "match_pattern": "regex"           }         }],         "_all": {           "enabled": false         },         "properties": {           "query": {             "properties": {               "filtered": {                 "properties": {                   "filter": {                     "properties": {                       "ids": {                         "properties": {                           "values": {                             "type": "string"                           }                         }                       }                     }                   },                   "query": {                     "properties": {                       "match_all": {                         "type": "object"                       }                     }                   }                 }               },               "match_all": {                 "type": "object"               }             }           },           "source": {             "dynamic": "true",             "properties": {               "post": {                 "dynamic": "true",                 "properties": {                   "_id": {                     "type": "string",                     "index": "not_analyzed"                   },                   "base_id": {                     "type": "string",                     "index": "not_analyzed"                   }                 }               }             }           },           "blog": {             "properties": {               "post": {                 "properties": {                   "_id": {                     "type": "string"                   },                   "notes": {                     "properties": {                       "main": {                         "properties": {                           "id": {                             "type": "string"                           },                           "message": {                             "type": "string"                           },                           "category": {                             "type": "string"                           }                         }                       },                       "cart": {                         "properties": {                           "id": {                             "type": "string"                           },                           "message": {                             "type": "string"                           },                           "category": {                             "type": "string"                           }                         }                       }                     }                   }                 }               }             }           }         }       }     }   } } 

you can use bool query must on ids , terms

post c1_2/test/_search {   "query": {     "bool": {       "must": [         {           "ids": {             "values": [               1,               2,               3             ]           }         },         {           "terms": {             "blog.post.notes.main.category": [               "categoryfilter"             ]           }         }       ]     }   } } 

but since have main , cart categories must use filter on each of them, in example filter on main categories, if need filter on both need use 1 more or filter filter on main or cart categories

also should know category should not_analyzed in order filter on "my super category" other wise query not working properly.

example

post c1_2/blog/1 {   "post": {     "notes": {       "main": [         {           "message": "blablabla",           "category": "test"         },         {           "message": "blablabla",           "category": "other"         }       ],       "cart": [         {           "message": "blablabla",           "category": "test"         },         {           "message": "blablabla",           "category": "other"         }       ]     }   } }  post c1_2/blog/2 {   "post": {     "notes": {       "main": [         {           "message": "blablabla",           "category": "second"         },         {           "message": "blablabla",           "category": "third"         }       ],       "cart": [         {           "message": "blablabla",           "category": "test"         },         {           "message": "blablabla",           "category": "other"         }       ]     }   } }   post c1_2/blog/_search {   "query": {     "bool": {       "must": [         {           "ids": {             "values": [               1,               2,               3             ]           }         },         {           "terms": {             "post.notes.main.category": [               "test"             ]           }         }       ]     }   } } 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -