my document schema looks this:
{ "store_id": 123, "franchise_id": 1, "name": "test", "location": "1.2,1.3" }
my use case revolves around finding stores. store can part of franchise or can independent (franchise_id = store_id). there can multiple different stores part of franchise , using franchise_id field identify store belongs franchise.
while searching store name , user location, want de-duplicate results based on franchise id.
now given location, distance range , name of store input want find stores grouped franchise_id such either get
- documents lie within range
or if no store present within range franchise_id
- the store doc minimum distance specified location
i've tried out reading aggregations not able figure out. appreciated.
you can group/deduplicate stores franchise_id
using terms
aggregation , within top hits
aggregation. see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html
Comments
Post a Comment