Skip to content

Instantly share code, notes, and snippets.

@eddiejaoude
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddiejaoude/8e7f31121ce075cc392c to your computer and use it in GitHub Desktop.
Save eddiejaoude/8e7f31121ce075cc392c to your computer and use it in GitHub Desktop.
Geo location on ElasticSearch

The following json data, mapping & agg request in ElasticSearch returns no results, but it should?

// ...
"_source":{
   "data":{
      "created_on": "2015-03-18T15:29:27",
      "county": "Halton",
      "region": "North West",
      "population": 125700,
      "location":{"lat": 43.5325372, "lon": -79.8744836}
   }
}
// ...
{
  "size": 0,
  "aggs": {
    "location": {
      "geohash_grid": {
        "field": "location"
      }
    }
  }
}
@eddiejaoude
Copy link
Author

Response with no results...

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 348,
        "max_score": 0,
        "hits": [
        ]
    },
    "aggregations": {
        "location": {
            "buckets": [
            ]
        }
    }
}

@eddiejaoude
Copy link
Author

Mapping...

{
    "population": {
        "mappings": {
            "uk": {
                "properties": {
                    "data": {
                        "properties": {
                            "county": {
                                "type": "string"
                            },
                            "created_on": {
                                "type": "date",
                                "format": "dateOptionalTime"
                            },
                            "location": {
                                "properties": {
                                    "lat": {
                                        "type": "double"
                                    },
                                    "lon": {
                                        "type": "double"
                                    }
                                }
                            },
                            "population": {
                                "type": "long"
                            },
                            "region": {
                                "type": "string"
                            }
                        }
                    },
                    "location": {
                        "type": "geo_point"
                    }
                }
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment