在[field]下应为[START_OBJECT],但在[geohash_grid]中获得了[VALUE_STRING]

时间:2019-01-21 10:00:03

标签: elasticsearch elasticsearch-aggregation geohashing

我需要在限制区域中获取序列号(或序列号)的最后注册记录,我还应根据地图中的缩放精度将这些记录聚类。 我正在使用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
            }
          }
        }
      }
    }
  }
}

在此查询中,首先,我根据文档的序列号和位置来限制文档,因此,我按序列号对查询进行分组,并按createate进行排序,以获取该区域中每个序列号的最后注册记录。 问题出在查询的最后一部分,当我应该用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

0 个答案:

没有答案