After applying this mapping to the desired index I insert document
with a field like "location" : "40.060008,23.461561".
Searching on this index works fine, as soon as I want to add e.g.
geo_bbox filter to this query I am getting an exception like
"org.elasticsearch.action.search.SearchPhaseExecutionException: Failed
to execute phase [query], total failure; shardFailures
{[KDmzsTNZSLO35OKUl7vc6A][picture][11]: SearchParseException[[picture]
[11]: query[+PLACE:greece],from[-1],size[100000]: Parse Failure
[Failed to parse source [na]]]; nested:
QueryParsingException[[picture] failed to find geo_point field
[GeoBoundingBoxFilter]]; }"
Ok, I spent some more time on this, obviously the problem is not the
mapping, but the added filter. I have a mapping on the index, I can do
filtered search queries using curl. I tried the following to rebuild
this using the Java API
get a Filter
public FilterBuilder getGeoBoundingBoxFilter (double bottomRightLon,
double bottomRightLat, double topLeftLon, double topLeftLat) {
GeoBoundingBoxFilterBuilder geoBox = new
GeoBoundingBoxFilterBuilder("GeoBoundingBoxFilter");
geoBox.bottomRight( bottomRightLat, bottomRightLon);
geoBox.topLeft(topLeftLat, topLeftLon);
return geoBox;
}
create a working search request
SearchRequestBuilder request = ... (runs, delivering wanted
results)
add the filter to the request
request.setFilter(filter); (Filter is returned from step 1)
execute this request
SearchResponse response = request.execute().actionGet();
The exception is the same as above, stating that no geo_point can be
found. Can anyone give me a hint what I am doing wrong or why I can do
this filtered request with curl but not with the Java API?
The parameter the GeoBoundingBoxFilterBuilder accepts is the field name, so
you should pass there "location". A note on using the builder APIs, use
QueryBuiders/FilterBuilders for static construction method for
queries/filters. And, you can chain the methods. This should make things
more readable and people will be less appalled by "that Java code"
Ok, I spent some more time on this, obviously the problem is not the
mapping, but the added filter. I have a mapping on the index, I can do
filtered search queries using curl. I tried the following to rebuild
this using the Java API
get a Filter
public FilterBuilder getGeoBoundingBoxFilter (double bottomRightLon,
double bottomRightLat, double topLeftLon, double topLeftLat) {
GeoBoundingBoxFilterBuilder geoBox = new
GeoBoundingBoxFilterBuilder("GeoBoundingBoxFilter");
geoBox.bottomRight( bottomRightLat, bottomRightLon);
geoBox.topLeft(topLeftLat, topLeftLon);
return geoBox;
}
create a working search request
SearchRequestBuilder request = ... (runs, delivering wanted
results)
add the filter to the request
request.setFilter(filter); (Filter is returned from step 1)
execute this request
SearchResponse response = request.execute().actionGet();
The exception is the same as above, stating that no geo_point can be
found. Can anyone give me a hint what I am doing wrong or why I can do
this filtered request with curl but not with the Java API?
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.