CodexBloom - Programming Q&A Platform

Elasticsearch 8.5 Returns Empty Results When Using Filtered Queries with Geo Distance

👀 Views: 85 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-16
elasticsearch geo-distance filter query json

I'm upgrading from an older version and I'm sure I'm missing something obvious here, but After trying multiple solutions online, I still can't figure this out... I'm working with Elasticsearch 8.5 and I'm working with an scenario where a filtered query that includes a geo distance filter returns no results, even though I can see documents in the index that should match the criteria. I'm using a mapping which defines a `location` field as a `geo_point` and I've indexed several documents with this field properly populated. Here's the query I'm executing: ```json { "query": { "bool": { "filter": [ { "geo_distance": { "distance": "5km", "location": { "lat": 40.712776, "lon": -74.005974 } } }, { "term": { "status": "active" } } ] } } } ``` For context, here are the documents I have indexed: ```json { "status": "active", "location": { "lat": 40.713, "lon": -74.006 } } { "status": "inactive", "location": { "lat": 40.800, "lon": -74.020 } } ``` Despite having a document that is marked as `active` and is within the specified distance from the location, the query always returns an empty result set. I've double-checked that the coordinates are indeed correct and the document exists in the index. I also tried simplifying the query to only the geo distance filter, and it still returned no results: ```json { "query": { "geo_distance": { "distance": "5km", "location": { "lat": 40.712776, "lon": -74.005974 } } } } ``` Am I missing something in my query, or is there a potential configuration scenario with my Elasticsearch cluster? I would appreciate any insights or debugging tips here. This is part of a larger service I'm building. This is part of a larger CLI tool I'm building. What am I doing wrong?