首页 文章

如何在Elasticsearch结果中返回geo_point的geohash?

提问于
浏览
0

如何在Elasticsearch结果中返回geo_point的geohash?

例如,位置字段是纬度/经度值 . 如何在结果中添加此字段的geohash?

1 回答

  • 1

    您需要在查询中添加 fielddata_fields ,如下所示:

    POST /index/_search
    {
      "query": {
        "match_all": {}
      },
      "fielddata_fields": [
        "location.geohash"
      ]
    }
    

    你会得到这样的东西,_2542440_和 fielddata_fields 中的地理位置

    {
      "hits": {
        "total": 1,
        "max_score": 1,
        "hits": [
          {
            "_index": "test",
            "_type": "test",
            "_id": "1",
            "_score": 1,
            "_source": {
              "location": "13.0009316,77.5947316"
            },
            "fields": {
              "location.geohash": [
                "t",
                "td",
                "tdr",
                "tdr1",
                "tdr1v",
                "tdr1vw",
                "tdr1vww",
                "tdr1vwwz",
                "tdr1vwwzb",
                "tdr1vwwzbm"
              ]
            }
          }
        ]
      }
    }
    

相关问题