ElasticSearch NEST - Search on multiple types but apply filter on selected Type alone -


i looking achieve single query search , filtering. expected when applied filtering, filter condition applied types got result of document have filtered property , value .

for example,

here searched in 3 types (product,category,manufacturer)

get /my-index/product,category,manufacturer/_search {     "query": {         "filtered": {            "query": {...}, //--> search word present in types            "filter": {                 "term": {                   "productfield": "value"                }            }         }     } } 

here got result of product type because product type contains field 'productfield' , has value 'value'.

what expecting is, with single query, fetch types results(product,category,manufacturer), satisfying search query , apply filtering on product.

so doubt

is there way in elastic search apply filtering on specific type search results alone applying types?

yes, can use type query achieve that. in filter, have bool/should clause selects either category or manufacturer without other conditions, or product documents having productfield: value:

post /my-index/product,category,manufacturer/_search {   "query": {     "filtered": {       "query": {},       "filter": {         "bool": {           "minimum_should_match": 1,           "should": [             {               "type": {                 "value": "category"               }             },             {               "type": {                 "value": "manufacturer"               }             },             {               "bool": {                 "must": [                   {                     "type": {                       "value": "product"                     }                   },                   {                     "term": {                       "productfield": "value"                     }                   }                 ]               }             }           ]         }       }     }   } } 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -