首页 > 解决方案 > [field] 下应为 [START_OBJECT],但在 [geohash_grid] 中得到了 [VALUE_STRING]

问题描述

我需要在受限区域中获取序列号或序列号的最后注册记录,我还应该根据地图中的缩放精度对这些记录进行聚类。我正在使用 Elasticsearch,并且我已经将我的文档映射成这种形状:

{
  "mappings": {
    "AssetStatus": {
      "properties": {
        "location": {
          "type": "geo_point"
        },
        "createdate": {
          "type": "date"
        },
        "serialnumber": {
          "type": "text",
          "fielddata": "true"
        }
      }
    }
  }
}

因此,我写了这个查询。

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "serialnumber": "sn2"
          }
        },
        {
          "geo_bounding_box": {
            "location": {
              "top_left": "52.4, 4.9",
              "bottom_right": "52.3, 5.0"
            }
          }
        }
      ],
      "must_not": [],
      "should": []
    }
  },
  "from": 0,
  "size": 0,
  "aggregations": {
    "SerialNumberGroups": {
      "terms": {
        "field": "serialnumber"
      },
      "aggs": {
        "tops": {
          "top_hits": {
            "sort": [
              {
                "createdate": {
                  "order": "desc"
                }
              }
            ],
            "size": 1
          },
          "aggs": {
            "geohash_grid": {
              "field": "location",
              "precision": 12
            }
          }
        }
      }
    }
  }
}

在这个查询中,首先我限制文档依赖于它们的序列号和它们的位置,因此我按序列号按查询分组并按createdate 排序以获取该区域中每个序列号的最后注册记录。问题出在查询的最后一部分,当我应该使用 geohash_grid 对结果进行聚类时。我得到这个错误

"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "Expected [START_OBJECT] under [field], but got a [VALUE_STRING] in [geohash_grid]",
"line": 1,
"col": 374
}
],
"type": "parsing_exception",
"reason": "Expected [START_OBJECT] under [field], but got a [VALUE_STRING] in [geohash_grid]",
"line": 1,
"col": 374
},
"status": 400

标签: elasticsearchelasticsearch-aggregationgeohashing

解决方案


推荐阅读