Linh Nguyen
Linh Nguyen

Reputation: 659

Different formats of geo_point type?

From the documentation here: http://www.elasticsearch.org/guide/reference/mapping/geo-point-type.html

It says geo_point accept different format. Ex: these two are supported

  1. "location" : "-71.34, 41.12"

  2. "location" : { "lat" : 41.12, "lon" : -71.34 }

I want to ask if these two are the same? I'm using ES 0.17.6 and having this problem:

When I index using the (1) format, I can't search with (2) format. If I use (1) format to search again, it is successful.

For example: If I index with (2) format:

curl -XPUT 'http://localhost:9200/twitter/pin/1' -d '
{
    "pin" : {
        "location" : {
                        lat: 41.12,
                        lon: -71.34
                },
        "tag" : ["food", "family"],
        "text" : "my favorite family restaurant"
    }
}' 

I can't search with this (1) format

curl -XGET 'http://localhost:9200/twitter/pin/_search' -d '
{
        "query": {
                "filtered" : {
                        "query" : {
                                "field" : { "text" : "restaurant" }
                        },
                        "filter" : {
                                "geo_distance" : {
                                        "distance" : "12km",
                                        "pin.location" : "-71.34, 41.12"
                                }
                        }
                }
        }
}
' 

And it will be successful if I search using (2) format:

2. "pin.location" : {
            "lat" : 41.12,
            "lon" : -71.34
    }

Upvotes: 0

Views: 677

Answers (1)

imotov
imotov

Reputation: 30163

When geo_point is represented as a string, it should follow lat lon format: "pin.location" : "41.12, -71.34"

Upvotes: 2

Related Questions