Elasticsearch geo_bounding_box查询报错问题求助
geo_bounding_box Parsing Error with Array Fields in Elasticsearch Got it, let's work through this parsing error you're hitting. That [bool] malformed query error usually means your query structure has a syntax hiccup—most likely because you're not handling the geo_times array field correctly, or there's a missing/closing bracket somewhere in your bool query.
First, Let's Diagnose the Root Cause
The error message says Elasticsearch expected an END_OBJECT but found a FIELD_NAME, which typically happens when:
- You’ve placed a field directly under the
boolclause instead of insidefilter,must, or another valid sub-clause - Your
geo_bounding_boxfilter is pointing to an array field without specifying the nested geo point path correctly - You have mismatched curly braces or brackets breaking the JSON structure
Since you mentioned geo_times is an array of objects, we need to make sure we're querying the geo point inside those objects properly.
Step 1: Confirm Your Mapping First
First, double-check that the geo field inside geo_times is mapped as a geo_point type. If geo_times needs to preserve the relationship between its nested fields (like the geo point and a timestamp), it should be a nested type. Here’s what a valid mapping might look like:
{ "mappings": { "properties": { "geo_times": { "type": "nested", "properties": { "location": { // Replace with your actual geo field name "type": "geo_point" }, "timestamp": { "type": "date" } } } } } }
Step 2: Correct Query Examples
Depending on whether geo_times is a nested type or a plain array, use one of these queries:
Case 1: geo_times is a Plain Array (Non-Nested)
Elasticsearch flattens plain arrays, so you can directly target the geo point inside the array using dot notation:
{ "query": { "bool": { "filter": [ { "geo_bounding_box": { "geo_times.location": { // Path to your geo point inside the array "top_left": { "lat": 40.73, "lon": -74.1 }, "bottom_right": { "lat": 40.01, "lon": -73.99 } } } }, // Add your other working query clauses here ] } } }
Case 2: geo_times is a Nested Type
If you need to query the geo point alongside other fields in the same array element (e.g., filter by geo AND timestamp), wrap the geo_bounding_box in a nested query:
{ "query": { "bool": { "filter": [ { "nested": { "path": "geo_times", "query": { "geo_bounding_box": { "geo_times.location": { "top_left": { "lat": 40.73, "lon": -74.1 }, "bottom_right": { "lat": 40.01, "lon": -73.99 } } } } } }, // Your other query clauses go here ] } } }
Quick Syntax Checks to Avoid the Error
- Make sure all query clauses are inside
filter,must, orshouldarrays under theboolquery—never directly underboolitself - Verify all curly braces and brackets are properly closed (a common culprit for parsing errors)
- Double-check the path to your geo field matches exactly what’s in your mapping (case-sensitive!)
内容的提问来源于stack exchange,提问作者gunner_dev

