Creating Dynamic Facets in Elasticsearch -
i want dynamically create facetts nested type has dynamic attributes.
suppose these articles in index , i'm searching name , brand:
{ name: iphone 16gb brand: apple type: smartphone attributes: { color: white } } { name: ipad brand: apple type: tablet attributes: { color: black } } { name: cruzer usb 16gb brand: sandisk type: usb-stick attributes: { color: black capacity: 16gb usb-standard: usb 2.0 } } { name: cruzer usb 16gb brand: sandisk type: usb-stick attributes: { color: red capacity: 16gb usb-standard: usb 3.0 } }
now, if i'm searching 'apple' want have search result has following facets:
brand: apple 2 type: smartphone 1 tablet 1 color: black 1 white 1
a search '16gb' should include facets:
brand: apple 1 sandisk 2 type: smartphone 1 usb-stick 2 color: black 1 white 1 red 1 capacity: 16gb 2 usb-standard: usb 3.0 1 usb 2.0 2
likewise, every article can have arbitrary attributes.
the facetted search brand , type easy, how attrubutes? possible elasticsearch?
i hope can unterstand mean...
try below
post _search { "query": { "query_string": { "query": "apple" } }, "facets": { "tags": { "terms": { "fields": ["name","brand","type","attributes.color"] } } } }
Comments
Post a Comment