1
votes

I am newbie to ES. I was trying to write java program to do geosearch using ES against MongoDB(installed river plugin etc and able to get the normal search using java program). I have a collection (table) in mongodb which has latitide and longitude values stored.Now I want to retreive the records based on lat and long which I am passing from Java program.

    FilterBuilder filter =  FilterBuilders.geoDistanceFilter("pin.location").lat(10).lon(20).distance(5,DistanceUnit.KILOMETERS).geoDistance(GeoDistance.PLANE);

    SearchResponse response = client.prepareSearch(INDEX)
                                    .setTypes(TYPE)
                                    .setSearchType(SearchType.QUERY_AND_FETCH)
                                    .setQuery(matchAllQuery())
                                    .setPostFilter(filter)
                                    .setFrom(0).setSize(60).setExplain(true)
                                    .execute()
                                    .actionGet();

If I execute the above program, I am getting " QueryParsingException[[mongoindex] failed to find geo_point field [pin.location]];" what is this pin.location? Also my mongodb table has columns 'Latitude" and 'Longitude'. But in the above filter I have 'lat(10).lon(20)'. I am missing something here. Please help me to understand. Any quick help highly appreciated.

Full stack tarce:

},"explain":true}]]]; nested: QueryParsingException[[mongoindex] failed to find geo_point field [pin.location]]; } at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:233) at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$1.onFailure(TransportSearchTypeAction.java:179) at org.elasticsearch.search.action.SearchServiceTransportAction$12.handleException(SearchServiceTransportAction.java:351) at org.elasticsearch.transport.netty.MessageChannelHandler.handleException(MessageChannelHandler.java:185) at org.elasticsearch.transport.netty.MessageChannelHandler.handlerResponseError(MessageChannelHandler.java:175) at org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:125) at org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791) at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:296) at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462) at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:443) at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303) at org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559) at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:268) at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:255) at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88) at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108) at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318) at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89) at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178) at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108) at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

Thanks, Sri

2
Before you start writing Java code, can you create an HTTP request that makes the same query to ES ? something like: http://url-to-es/index/document?query=...Nir Alfasi

2 Answers

1
votes

The filter you are creating is based on the field pin.location

FilterBuilders.geoDistanceFilter("pin.location")

That answers your question about that this pin.location is. Start looking at the mapping of your index to see if the field you are adding to elasticsearch is of type geo_point. I haven't used the mongo river myself, but according to this issue you have to provide your own mapping.

https://github.com/richardwilly98/elasticsearch-river-mongodb/issues/218#issuecomment-35824681

Below an example coming from the mentioned post above:

curl -XPUT 'http://localhost:9200/location_test' -d '
{
    "mappings": {
        "places": {
            "properties": {
               "location": {
                    "type": "geo_point"
                }
            }
        }
    }
}
'

More information about geo_point in elasticsearch can be found here: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-geo-point-type.html

0
votes

Thanks for the information. Issue is resolved. Worked fine with the following configuration.

curl -XPUT 'http://localhost:9200/myindex' -d '
{
   "settings" : {
        "number_of_shards" : 2,
        "number_of_replicas" : 1
    },
   "mappings" : {
      "my_details" : {
          "properties" : {
              "my_id" : {"type" : "integer", "store" : "yes" , "index":"not_analyzed"},
              "location" : {"type" : "geo_point", "store" : "yes", "index":"not_analyzed"}
          }
      }
  }

}'

curl -XPUT 'http://localhost:9200/_river/my_river/_meta' -d '
{
    "type": "mongodb",
    "mongodb": {
        "db": "MyDatabase",
        "collection": "my_details"
    },
    "index": {
        "name": "myindex",
        "type": "my_details"
    }

}'

Note: MongoDb has 'my_details' collection in 'MyDatabase'.
Cheers, Cdhar