使用elasticsearch中的聚合搜索geo_distance

时间:2016-06-04 21:00:42

标签: elasticsearch

我尝试进行地理空间搜索,因为我可以使用相同的listing_id获得多次点击,我希望按listing_id对结果进行分组。

{
"query": {
    "filtered": {
        "filter": {
            "geo_distance": {
                "distance": "24km",
                "location":[39.91774, -75.03005]
            }
        }
    },
    "aggs": {
        "group_by_listing": {
            "terms": { "field": "listing_id" }
        }
    }
}

如果我在没有聚合的情况下进行搜索,结果会很好,但每当我尝试添加聚合节点时,我都会收到以下错误 {"error":{"root_cause":[{"type":"parse_exception","reason":"failed to parse search source. expected field name but got [START_OBJECT]"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"listings","node":"n0nkglP4T6iik-Z-XyYspA","reason":{"type":"parse_exception","reason":"failed to parse search source. expected field name but got [START_OBJECT]"}}]},"status":400}

这是卷曲请求: curl -XPOST http://192.168.10.10:9200/listings/route/_search -d '{"query":{"filtered":{"filter":{"geo_distance":{"distance":"24km","location":[39.91774, -75.03005]}}},"aggs":{"group_by_listings":{"terms":{"field":"listing_id"}}}}}'

1 个答案:

答案 0 :(得分:1)

您只需将aggs移出query部分,就像这样:

{
  "query": {
    "filtered": {
      "filter": {
        "geo_distance": {
          "distance": "24km",
          "location": [
            39.91774,
            -75.03005
          ]
        }
      }
    }
  },
  "aggs": {
    "group_by_listing": {
      "terms": {
        "field": "listing_id"
      }
    }
  }
}