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

Elasticsearch查询报错排查:geo_bounding_box配置与filter语法问题

Elasticsearch查询错误排查与geo_bounding_box正确配置

错误原因分析

  1. JSON语法错误:filter数组中,geo_bounding_box对象和后续的match对象之间缺少逗号,导致Elasticsearch解析JSON时失败,直接触发了x_content_parse_exception错误。
  2. 地理坐标配置错误:
    • 你把纬度(lat)和经度(lon)的位置写反了,纬度的合法范围是[-90, 90],你写的-105.03197389是合法经度值,但放在lat字段里超出了范围。
    • 边界框的top_left(西北顶点)需要满足纬度更高(更北)、经度更西(数值更小,西经为负);bottom_right(东南顶点)需要满足纬度更低(更南)、经度更东(数值更大),你当前的坐标数值不符合这个逻辑,就算语法修复也查不到正确结果。

修正后的查询语句

search = {
  "query": {
    "bool": {
      "filter": [
        {
          "range": {
            "created_at": {
              "gte":"2013-12-31T07:14:22+00:00",
              "lt":"2015-12-31T07:14:22+00:00"
            }
          }
        },
        {
          "geo_bounding_box": {
            "coordinates": {
              "top_left": {
                "lat": 40.01724753,  // 更北的纬度
                "lon": -105.282502   // 更西的经度
              },
              "bottom_right": {
                "lat": 39.93687082,  // 更南的纬度
                "lon": -105.03197389 // 更东的经度
              }
            }
          }
        },
        {
          "match": {
            "text": "Story"
          }
        }
      ]
    }
  }
}

geo_bounding_box正确配置方式

  • 确保目标字段(这里是coordinates)的映射类型为geo_point,如果不是,需要先修改索引映射。
  • 边界框顶点规则:
    • top_left是西北顶点:lat值必须大于bottom_right.lat(纬度越大越靠北);lon值必须小于bottom_right.lon(西经数值为负,数值越小越靠西)。
    • 坐标值必须符合范围:纬度lat ∈ [-90, 90],经度lon ∈ [-180, 180],严禁lat和lon位置写反。

内容的提问来源于stack exchange,提问作者Ghaid_SS

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 14:35:21