Mapping and geo-filter

Hi,

I am having a problem with a mapping defining a geo_point, but no
ideas anymore where the problem is. Maybe someone can give me a hint.

I am creating a mapping for an index where I want to set a field
"location" as a geo_point

public static XContentBuilder createGeoMapping (IndexType index)

throws IOException {
return JsonXContent.contentBuilder()
.startObject()
.startObject(ElasticSearchIndex.getType(index))
.startObject("properties")
.startObject("location")
.field("type", "geo_point")
.endObject()
.endObject()
.endObject()
.endObject();
}

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]]; }"

Can anyone give me a hint on this?

Thanks in advance!
Andrej

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

  1. 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;
    }

  2. create a working search request
    SearchRequestBuilder request = ... (runs, delivering wanted
    results)

  3. add the filter to the request
    request.setFilter(filter); (Filter is returned from step 1)

  4. 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" :slight_smile:

On Thu, Aug 4, 2011 at 5:24 PM, Andrej Rosenheinrich <
andrej.rosenheinrich@unister.de> wrote:

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

  1. 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;
    }

  2. create a working search request
    SearchRequestBuilder request = ... (runs, delivering wanted
    results)

  3. add the filter to the request
    request.setFilter(filter); (Filter is returned from step 1)

  4. 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?