elasticsearch - Conditional geo-location based search of documents with aggregation -


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

  1. documents lie within range

or if no store present within range franchise_id

  1. 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 hitsaggregation. see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -