无法使用geo_distance进行筛选查询。 Elasticsearch

时间:2013-04-22 22:40:31

标签: elasticsearch

这是我的问题。我有一些数据存储在字段"location"的索引中。 这是映射

{
    "data":{
        "properties":{
        ...
        "location":{
            "type": "geo_point",
            "lat_lon": true,
            "store": "yes"
        },
        ...
        }
    }
}

以下是索引

中存在的数据示例
{
  "metadata": {
    "total": 2887,
    "maxScore": 4.8634477
  },
  "data": [
    {
      "_index": "data",
      "_type": "data",
      "_id": "8-HtWNILQrqrobwchhgNIQ",
      "_score": 4.8634477,
      "_source": {
        "generique": "Chemin",
        "_datasetId": "5175b2b4a652945a0500000d",
        "liaison": "",
        "specifique": "Sainte-Foy",
        "direction": "",
        "nomTopo": "Chemin Sainte-Foy",
        "ville": "Québec",
        "arrond": "Sainte-Foy-Sillery-Cap-Rouge",
        "location": {
          "lon": -71.322135,
          "lat": 46.768526
        }
      }
    },
    {
      "_index": "data",
      "_type": "data",
      "_id": "sSZ3u-uDQIuPDc2qnPir0g",
      "_score": 4.8634477,
      "_source": {
        "generique": "Chemin",
        "_datasetId": "5175b2b4a652945a0500000d",
        "liaison": "",
        "specifique": "Sainte-Foy",
        "direction": "",
        "nomTopo": "Chemin Sainte-Foy",
        "ville": "Québec",
        "arrond": "Sainte-Foy-Sillery-Cap-Rouge",
        "location": {
          "lon": -71.286977,
          "lat": 46.784508
        }
      }
    }
  ]
}

如果我想使用geo_distance执行请求,则会返回无关数据。

这是请求

{
  "query": {
    "filtered": {
      "query_string": {
        "query": "_datasetId:5175b2b4a652945a0500000d"
      },
      "filter": {
        "geo_distance": {
          "location": {
            "lat": 46.815569,
            "lon": -71.208401
          },
          "distance": "1km"
        }
      }
    }
  }
}

收到的数据不包含权限"_datasetId",并且不包含"location"与查询中给出的数据关闭。

我希望我足够清楚 感谢。

1 个答案:

答案 0 :(得分:3)

我实际上从邮件列表中得到了答案,我想分享它。

https://groups.google.com/forum/?fromgroups=#!topic/elasticsearch/cxZMZX-bWFA