Geo search not working for current version of ElasticSearch (< 0.11.0)

I am very new to ElasticSearch, and trying to test the geo
functionality. I've looked at the documentation and other posts and
cobbled together a test that fails on 0.14.4. Going back through the
older versions, the following test does work with 0.11.0. I understand
the geo functionality changed with the bump to 0.12.0, but I cannot
figure out how the new syntax is supposed to work.

curl -XPUT 'http://localhost:9200/test/'

curl -XPUT 'http://localhost:9200/test/pins/_mapping' -d '{
"pin" : {
"properties" : {
"location" : {
"type" : "geo_point"
}
}
}
}'

curl -XGET 'http://localhost:9200/test/pins/_mapping?pretty=true'

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

curl -XGET 'http://localhost:9200/test/pins/_search' -d '{
"query" : {
"filtered" : {
"query" : {
"field" : { "text" : "restaurant" }
},
"filter" : {
"geo_distance" : {
"distance" : "120km",
"pin.location" : {
"lat" : 40,
"lon" : -70
}
}
}
}
}
}'

Result:

{"error":"SearchPhaseExecutionException[Failed to execute phase
[query], total failure; shardFailures {[PSO9xzYtTPapsrT_ihhv_Q][test]
[0]: SearchParseException[[test][0]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query" : { \n "filtered" :
{ \n "query" : { \n "field" : { "text" : "restaurant
" } \n }, \n "filter" : { \n "geo_distance" :
{ \n "distance" : "120km", \n "pin.location" :
{ \n "lat" : 40, \n "lon" : -70 \n }
\n }\n }\n }\n }\n}]]]; nested:
QueryParsingException[[test] failed to find geo_point field
[pin.location]]; }{[PSO9xzYtTPapsrT_ihhv_Q][test][1]:
SearchParseException[[test][1]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query" : { \n "filtered" :
{ \n "query" : { \n "field" : { "text" : "restaurant
" } \n }, \n "filter" : { \n "geo_distance" :
{ \n "distance" : "120km", \n "pin.location" :
{ \n "lat" : 40, \n "lon" : -70 \n }
\n }\n }\n }\n }\n}]]]; nested:
QueryParsingException[[test] failed to find geo_point field
[pin.location]]; }{[PSO9xzYtTPapsrT_ihhv_Q][test][2]:
SearchParseException[[test][2]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query" : { \n "filtered" :
{ \n "query" : { \n "field" : { "text" : "restaurant
" } \n }, \n "filter" : { \n "geo_distance" :
{ \n "distance" : "120km", \n "pin.location" :
{ \n "lat" : 40, \n "lon" : -70 \n }
\n }\n }\n }\n }\n}]]]; nested:
QueryParsingException[[test] failed to find geo_point field
[pin.location]]; }{[PSO9xzYtTPapsrT_ihhv_Q][test][3]:
SearchParseException[[test][3]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query" : { \n "filtered" :
{ \n "query" : { \n "field" : { "text" : "restaurant
" } \n }, \n "filter" : { \n "geo_distance" :
{ \n "distance" : "120km", \n "pin.location" :
{ \n "lat" : 40, \n "lon" : -70 \n }
\n }\n }\n }\n }\n}]]]; nested:
QueryParsingException[[test] failed to find geo_point field
[pin.location]]; }{[PSO9xzYtTPapsrT_ihhv_Q][test][4]:
SearchParseException[[test][4]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query" : { \n "filtered" :
{ \n "query" : { \n "field" : { "text" : "restaurant
" } \n }, \n "filter" : { \n "geo_distance" :
{ \n "distance" : "120km", \n "pin.location" :
{ \n "lat" : 40, \n "lon" : -70 \n }
\n }\n }\n }\n }\n}]]]; nested:
QueryParsingException[[test] failed to find geo_point field
[pin.location]]; }]"}

From the log (one for each shard):

[2011-02-04 16:58:49,392][DEBUG][action.search.type ] [Magik]
[test][0], node[PSO9xzYtTPapsrT_ihhv_Q], [P], s[STARTED]: Failed to
execute [org.elasticsearch.action.search.SearchRequest@7654a50]
org.elasticsearch.search.SearchParseException: [test][0]:
from[-1],size[-1]: Parse Failure [Failed to parse source [{
"query" : {
"filtered" : {
"query" : {
"field" : { "text" : "restaurant" }
},
"filter" : {
"geo_distance" : {
"distance" : "120km",
"pin.location" : {
"lat" : 40,
"lon" : -70
}
}
}
}
}
}]]
at
org.elasticsearch.search.SearchService.parseSource(SearchService.java:
420)
at
org.elasticsearch.search.SearchService.createContext(SearchService.java:
335)
at
org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:
169)
at
org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:
131)
at
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction
$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:
76)
at org.elasticsearch.action.search.type.TransportSearchTypeAction
$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:193)
at org.elasticsearch.action.search.type.TransportSearchTypeAction
$BaseAsyncAction.access$000(TransportSearchTypeAction.java:77)
at org.elasticsearch.action.search.type.TransportSearchTypeAction
$BaseAsyncAction$1.run(TransportSearchTypeAction.java:152)
at java.util.concurrent.ThreadPoolExecutor
$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor
$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Caused by: org.elasticsearch.index.query.QueryParsingException: [test]
failed to find geo_point field [pin.location]
at
org.elasticsearch.index.query.xcontent.GeoDistanceFilterParser.parse(GeoDistanceFilterParser.java:
163)
at
org.elasticsearch.index.query.xcontent.QueryParseContext.parseInnerFilter(QueryParseContext.java:
193)
at
org.elasticsearch.index.query.xcontent.FilteredQueryParser.parse(FilteredQueryParser.java:
67)
at
org.elasticsearch.index.query.xcontent.QueryParseContext.parseInnerQuery(QueryParseContext.java:
167)
at
org.elasticsearch.index.query.xcontent.XContentIndexQueryParser.parse(XContentIndexQueryParser.java:
234)
at
org.elasticsearch.index.query.xcontent.XContentIndexQueryParser.parse(XContentIndexQueryParser.java:
214)
at
org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:
34)
at
org.elasticsearch.search.SearchService.parseSource(SearchService.java:
407)
... 10 more

Other relevant links, none of which are helping me grok this:


http://elasticsearch-users.115913.n3.nabble.com/Problem-with-geo-distance-filter-td1576354.html

You mapping was not processed because the top level name is "pin" and not "pins". You can always do a get mapping to check the actual mapping for a type in an index ES has.
On Saturday, February 5, 2011 at 3:02 AM, digsmahler wrote:

I am very new to Elasticsearch, and trying to test the geo
functionality. I've looked at the documentation and other posts and
cobbled together a test that fails on 0.14.4. Going back through the
older versions, the following test does work with 0.11.0. I understand
the geo functionality changed with the bump to 0.12.0, but I cannot
figure out how the new syntax is supposed to work.

curl -XPUT 'http://localhost:9200/test/'

curl -XPUT 'http://localhost:9200/test/pins/_mapping' -d '{
"pin" : {
"properties" : {
"location" : {
"type" : "geo_point"
}
}
}
}'

curl -XGET 'http://localhost:9200/test/pins/_mapping?pretty=true'

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

curl -XGET 'http://localhost:9200/test/pins/_search' -d '{
"query" : {
"filtered" : {
"query" : {
"field" : { "text" : "restaurant" }
},
"filter" : {
"geo_distance" : {
"distance" : "120km",
"pin.location" : {
"lat" : 40,
"lon" : -70
}
}
}
}
}
}'

Result:

{"error":"SearchPhaseExecutionException[Failed to execute phase
[query], total failure; shardFailures {[PSO9xzYtTPapsrT_ihhv_Q][test]
[0]: SearchParseException[[test][0]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query" : { \n "filtered" :
{ \n "query" : { \n "field" : { "text" : "restaurant
" } \n }, \n "filter" : { \n "geo_distance" :
{ \n "distance" : "120km", \n "pin.location" :
{ \n "lat" : 40, \n "lon" : -70 \n }
\n }\n }\n }\n }\n}]]]; nested:
QueryParsingException[[test] failed to find geo_point field
[pin.location]]; }{[PSO9xzYtTPapsrT_ihhv_Q][test][1]:
SearchParseException[[test][1]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query" : { \n "filtered" :
{ \n "query" : { \n "field" : { "text" : "restaurant
" } \n }, \n "filter" : { \n "geo_distance" :
{ \n "distance" : "120km", \n "pin.location" :
{ \n "lat" : 40, \n "lon" : -70 \n }
\n }\n }\n }\n }\n}]]]; nested:
QueryParsingException[[test] failed to find geo_point field
[pin.location]]; }{[PSO9xzYtTPapsrT_ihhv_Q][test][2]:
SearchParseException[[test][2]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query" : { \n "filtered" :
{ \n "query" : { \n "field" : { "text" : "restaurant
" } \n }, \n "filter" : { \n "geo_distance" :
{ \n "distance" : "120km", \n "pin.location" :
{ \n "lat" : 40, \n "lon" : -70 \n }
\n }\n }\n }\n }\n}]]]; nested:
QueryParsingException[[test] failed to find geo_point field
[pin.location]]; }{[PSO9xzYtTPapsrT_ihhv_Q][test][3]:
SearchParseException[[test][3]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query" : { \n "filtered" :
{ \n "query" : { \n "field" : { "text" : "restaurant
" } \n }, \n "filter" : { \n "geo_distance" :
{ \n "distance" : "120km", \n "pin.location" :
{ \n "lat" : 40, \n "lon" : -70 \n }
\n }\n }\n }\n }\n}]]]; nested:
QueryParsingException[[test] failed to find geo_point field
[pin.location]]; }{[PSO9xzYtTPapsrT_ihhv_Q][test][4]:
SearchParseException[[test][4]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query" : { \n "filtered" :
{ \n "query" : { \n "field" : { "text" : "restaurant
" } \n }, \n "filter" : { \n "geo_distance" :
{ \n "distance" : "120km", \n "pin.location" :
{ \n "lat" : 40, \n "lon" : -70 \n }
\n }\n }\n }\n }\n}]]]; nested:
QueryParsingException[[test] failed to find geo_point field
[pin.location]]; }]"}

From the log (one for each shard):

[2011-02-04 16:58:49,392][DEBUG][action.search.type ] [Magik]
[test][0], node[PSO9xzYtTPapsrT_ihhv_Q], [P], s[STARTED]: Failed to
execute [org.elasticsearch.action.search.SearchRequest@7654a50]
org.elasticsearch.search.SearchParseException: [test][0]:
from[-1],size[-1]: Parse Failure [Failed to parse source [{
"query" : {
"filtered" : {
"query" : {
"field" : { "text" : "restaurant" }
},
"filter" : {
"geo_distance" : {
"distance" : "120km",
"pin.location" : {
"lat" : 40,
"lon" : -70
}
}
}
}
}
}]]
at
org.elasticsearch.search.SearchService.parseSource(SearchService.java:
420)
at
org.elasticsearch.search.SearchService.createContext(SearchService.java:
335)
at
org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:
169)
at
org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:
131)
at
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction
$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:
76)
at org.elasticsearch.action.search.type.TransportSearchTypeAction
$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:193)
at org.elasticsearch.action.search.type.TransportSearchTypeAction
$BaseAsyncAction.access$000(TransportSearchTypeAction.java:77)
at org.elasticsearch.action.search.type.TransportSearchTypeAction
$BaseAsyncAction$1.run(TransportSearchTypeAction.java:152)
at java.util.concurrent.ThreadPoolExecutor
$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor
$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Caused by: org.elasticsearch.index.query.QueryParsingException: [test]
failed to find geo_point field [pin.location]
at
org.elasticsearch.index.query.xcontent.GeoDistanceFilterParser.parse(GeoDistanceFilterParser.java:
163)
at
org.elasticsearch.index.query.xcontent.QueryParseContext.parseInnerFilter(QueryParseContext.java:
193)
at
org.elasticsearch.index.query.xcontent.FilteredQueryParser.parse(FilteredQueryParser.java:
67)
at
org.elasticsearch.index.query.xcontent.QueryParseContext.parseInnerQuery(QueryParseContext.java:
167)
at
org.elasticsearch.index.query.xcontent.XContentIndexQueryParser.parse(XContentIndexQueryParser.java:
234)
at
org.elasticsearch.index.query.xcontent.XContentIndexQueryParser.parse(XContentIndexQueryParser.java:
214)
at
org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:
34)
at
org.elasticsearch.search.SearchService.parseSource(SearchService.java:
407)
... 10 more

Other relevant links, none of which are helping me grok this:

Geo Overhaul (work with multiple locations) · Issue #414 · elastic/elasticsearch · GitHub
http://elasticsearch-users.115913.n3.nabble.com/Problem-with-geo-distance-filter-td1576354.html

Solved. Thank you!