How to fetch unique geo codes from Elasticsearch? -


i'm new elasticsearch. i've created index & inserted documents following curl commands.

curl -xput 'localhost:9200/museums?pretty' -h 'content-type: application/json' -d' {     "mappings": {         "doc": {             "properties": {                 "location": {                     "type": "geo_point"                 }             }         }     } } ' curl -xpost 'localhost:9200/museums/doc/_bulk?refresh&pretty' -h 'content-type: application/json' -d' {"index":{"_id":1}} {"location": "52.374081,4.912350", "name": "nemo science museum"} {"index":{"_id":2}} {"location": "52.369219,4.901618", "name": "museum het rembrandthuis"} {"index":{"_id":3}} {"location": "52.371667,4.914722", "name": "nederlands scheepvaartmuseum"} {"index":{"_id":4}} {"location": "51.222900,4.405200", "name": "letterenhuis"} {"index":{"_id":5}} {"location": "48.861111,2.336389", "name": "musée du louvre"} {"index":{"_id":6}} {"location": "48.860000,2.327000", "name": "musée d\u0027orsay"} {"index":{"_id":7}} {"location": "52.374081,4.912350", "name": "nemo7 science museum"} {"index":{"_id":8}} {"location": "52.369219,4.901618", "name": "museum8 het rembrandthuis"} {"index":{"_id":9}} {"location": "52.371667,4.914722", "name": "nederlands9 scheepvaartmuseum"} {"index":{"_id":10}} {"location": "51.222900,4.405200", "name": "letterenhuis10"} {"index":{"_id":11}} {"location": "48.861111,2.336389", "name": "musée11 du louvre"} {"index":{"_id":12}} {"location": "48.860000,2.327000", "name": "musée12 d\u0027orsay"} ' 

if you'll see curl commands i've made duplicate documents & inserted also. now, want fetch documents having unique geo codes & apply sort(asc) on that.

i got 1 sample curl command following.

curl -xpost 'localhost:9200/museums/_search?size=0&pretty' -h 'content-type: application/json' -d' {     "aggs" : {         "rings_around_amsterdam" : {             "geo_distance" : {                 "field" : "location",                 "origin" : "52.3760, 4.894",                 "ranges" : [                     { "to" : 100000 },                     { "from" : 100000, "to" : 300000 },                     { "from" : 300000 }                 ]             }         }     } } ' 

but, uses range on that. want fetch unique geo codes & sort in ascending order. googled but, whatever i'm getting fetch unique documents works on text/numeric type documents. not on geo codes type document.

need help.

try :

curl -xpost 'localhost:9200/museums/_search?size=0&pretty' -h 'content-type: application/json' -d' {

    "size" : 0,     "aggs": {           "distinct_geo_distance" : {               "cardinality" : {                 "field" : "location"               }           }      } } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -