You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Elasticsearch geo_bounding_box查询报错问题求助

Fixing the 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 bool clause instead of inside filter, must, or another valid sub-clause
  • Your geo_bounding_box filter 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, or should arrays under the bool query—never directly under bool itself
  • 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 11:10:11