0

I'm trying to do a geospatial searce, since I can get multiple hits with the same listing_id I'd like to group the results by the listing_id.

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

If I search without the aggregation the results come back fine, but whenever I try adding an aggregation node I receive the following error {"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}

This is the curl request: 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 Answer 1

1

You simply need to move your aggs out of the query part, like this:

{
  "query": {
    "filtered": {
      "filter": {
        "geo_distance": {
          "distance": "24km",
          "location": [
            39.91774,
            -75.03005
          ]
        }
      }
    }
  },
  "aggs": {
    "group_by_listing": {
      "terms": {
        "field": "listing_id"
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.