Zero results for Geodistance filter


(Peter Webber) #1

I am using elasticSearch's Java API. What I want to do, is search for posts
that are around a certain point on in a city. Thus each post has a
coordinates field. Here's my code to achieve the mapping:

String mappingString =
        "{"
        +    "\"posts\" : {"
        +        "\"properties\" : {"
        +            "\"coordinates\" : {"
        +                "\"type\" : \"geo_point\""
        +            "}"
        +        "}"
        +    "}"
        +"}";     

Client.admin().indices().preparePutMapping("posts").setType("posts").setSource(mappingString).execute().actionGet
();

And here's the code I use for querying ElasticSearch:

GeoDistanceFilterBuilder gdFilter =   

FilterBuilders.geoDistanceFilter("posts.coordinates")
.point(lon, lat)
.distance(distanceInMeters, DistanceUnit.METERS)
.optimizeBbox("memory")
.geoDistance(GeoDistance.ARC);

SearchResponse response = Client.prepareSearch("posts")
    .setQuery(QueryBuilders.matchAllQuery())
    .setFilter(gdFilter)
    .setSize(100)
    .execute()
    .actionGet();

I verified with ElasticSearch Head that I indeed have posts in the index
that should pass the filter. But whatever values I use for the variables in
the query and the filter, I always get zero results. If I comment out
"setFilter(gdFilter)" I receive results, so the issue should be with the
filter or the mapping, I guess.

Can someone see, what I am doing wrong?

Many thanks!

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #2