我尝试进行地理空间搜索,因为我可以使用相同的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"}}}}}'
答案 0 :(得分:1)
您只需将aggs
移出query
部分,就像这样:
{
"query": {
"filtered": {
"filter": {
"geo_distance": {
"distance": "24km",
"location": [
39.91774,
-75.03005
]
}
}
}
},
"aggs": {
"group_by_listing": {
"terms": {
"field": "listing_id"
}
}
}
}