【问题标题】:mapping geo polygon Elastic Search/Kibana 5.3映射地理多边形 Elastic Search/Kibana 5.3
【发布时间】:2017-04-17 22:46:31
【问题描述】:

我有 20,000 个这种格式的 geojson 文件:

{
    "geometry": {
        "type": "Polygon",
        "coordinates": [
            [
                [long,lat],
                [long,lat],
                [long,lat],
                [long,lat],
                [long,lat]
            ]
        ]
    },

我用 geo_shape 和 geo_point 尝试的所有映射要么没有显示在 Kibana 中,要么显示在 kibana 中,但没有数据。将其映射到索引许多文件的最佳方法是什么? (如果没有好的方法,如果我不能使用所有坐标,我的下一个想法是为每个文件创建一个中心点。也许取第一个 long,lat 数组并将其作为每个 json 文件的 geo_point 中心点。不知道如何也可以解决这个问题)

这是我在不更改任何内容的情况下索引时来自 ES 的默认映射:

{
  "indexname" : {
    "mappings" : {
      "my_type" : {
        "properties" : {
          "geometry" : {
            "properties" : {
              "coordinates" : {
                "type" : "float"
              },
              "type" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              }
            }
          },

更新 这是我的新映射:

{
  "indexname" : {
    "mappings" : {
      "my_type" : {
        "properties" : {
          "geometry" : {
            "type" : "geo_shape",
            "tree" : "quadtree",
            "precision" : "1.0m"
          },
          "id" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },

但是,当我去 kibana 时,尝试在增强的 tilemap 上进行可视化时仍然出现错误:

No Compatible Fields: The "indexname" index pattern does not contain any of the following field types: geo_point

EDIT2 这是我创建映射的命令:

curl -XPUT "http://localhost:9200/indexname" -d "{\"mappings\" : {\"my_type\" : {\"properties\" : {\"geometry\" : {\"type\":\"geo_shape\", \"tree\": \"quadtree\", \"precision\": \"1m\"}}}}}"

我正在通过循环和发送发布请求来索引我的文件:

r = requests.post(url_of_index, data=file(jsonfiles).read()) 

当我尝试将类型更改为 geo_point 然后索引我的文件时,我遇到了映射器解析器异常。

【问题讨论】:

    标签: python elasticsearch kibana


    【解决方案1】:

    您需要做的是创建您自己的包含geo_shape 类型的映射,因为 ES 本身不会从您的 GeoJSON 文档中推断出来。

    PUT indexname
    {
      "mappings": {
        "my_type": {
          "properties": {
            "geometry": {
              "type": "geo_shape",
              "tree": "quadtree",
              "precision": "1m"
            }
          }
        }
      }
    }
    

    创建此索引和映射后,您将能够为您的 GeoJSON 文件编制索引:

    PUT indexname/my_type/1
    {
      "geometry": {
        "type": "Polygon",
        "coordinates": [
            [
                [long,lat],
                [long,lat],
                [long,lat],
                [long,lat],
                [long,lat]
            ]
        ]
      }
    }
    

    更新

    根据我们的讨论,您可能需要在映射中创建一个新的 geo_point 字段,如下所示:

    PUT indexname
    {
      "mappings": {
        "my_type": {
          "properties": {
            "location": {
              "type": "geo_point"
            },
            "geometry": {
              "type": "geo_shape",
              "tree": "quadtree",
              "precision": "1m"
            }
          }
        }
      }
    }
    

    然后从您的 Python 代码中,您需要通过读取 JSON 文件中的第一个坐标来创建该新字段,类似于下面的伪代码:

    import json
    
    doc = json.loads(file(jsonfiles).read())
    # create the new location field
    doc['location'] = doc['geometry']['coordinates'][0][0]
    r = requests.post(url_of_index, data=json.dumps(doc)) 
    

    【讨论】:

    • 我可以这样做,但仍然得到相同的错误 No Compatible Fields: The "indexname" index pattern does not contain any of the following field types: geo_point
    • 也许你应该更新你的问题并显示你正在运行的命令和你得到的错误。
    • 已更新——我想尝试在增强的瓷砖地图上可视化某些内容。但是,geo_shape 似乎不受支持。如何使用多边形数组作为一个点?
    • 你能显示你正在运行的命令来索引你的文档和你得到的错误吗?同时展示您在 Kibana 中尝试做的事情。我想了解为什么 ES/Kibana 抱怨 geo_point
    • 见上面的Edit2
    猜你喜欢
    • 1970-01-01
    • 2013-08-15
    • 1970-01-01
    • 1970-01-01
    • 2014-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    相关资源
    最近更新 更多