ElasticSearch错误:QueryParsingException [[mongoindex]无法找到geo_point字段[pin.location]];

时间:2015-02-09 07:36:27

标签: elasticsearch elasticsearch-jdbc-river

我是ES的新手。我正在尝试编写java程序来使用ES对MongoDB进行geosearch(安装了河流插件等,并且能够使用java程序进行正常搜索)。 我在mongodb中有一个集合(表),其中存储了latitide和经度值。现在我想根据我从Java程序传递的lat和long来检索记录。

    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();

如果我执行上述程序,我会得到" QueryParsingException [[mongoindex]无法找到geo_point字段[pin.location]];" 这个pin.location是什么?我的mongodb表也有专栏“Latitude"和经度'。但是在上面的过滤器中我有'lat(10).lon(20)'。我在这里遗漏了一些东西。 请帮我理解。任何快速帮助高度赞赏。

Full stack tarce:

}"解释":真}]]];嵌套:QueryParsingException [[mongoindex]无法找到geo_point字段[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)         在org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:125)         在org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)         在org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)         在org.elasticsearch.common.netty.channel.DefaultChannelPipeline $ DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)         在org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:296)         在org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462)         在org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:443)         在org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303)         在org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)         在org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)         在org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)         在org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:268)         在org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:255)         在org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)         在org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)         在org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318)         在org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)         在org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)         在org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)         在org.elasticsearch.common.netty.util.internal.DeadLockProofWorker $ 1.run(DeadLockProofWorker.java:42)         在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)         at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)         在java.lang.Thread.run(Thread.java:745)

谢谢, 斯

2 个答案:

答案 0 :(得分:1)

您正在创建的过滤器基于字段pin.location

FilterBuilders.geoDistanceFilter("pin.location")

这回答了你关于这个pin.location的问题。开始查看索引的映射,以查看要添加到elasticsearch的字段是否为 geo_point 类型。我自己没有使用过mongo河,但根据这个问题,你必须提供自己的地图。

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

以下上述帖子的示例:

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

有关elasticsearch中geo_point的更多信息,请访问: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-geo-point-type.html

答案 1 :(得分:0)

感谢您提供的信息。问题已解决。使用以下配置工作正常。

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

}'

注意:MongoDb有' my_details'收集在' MyDatabase' 干杯, Cdhar