我有20,000个以下格式的geojson文件:
{
"geometry": {
"type": "Polygon",
"coordinates": [
[
[long,lat],
[long,lat],
[long,lat],
[long,lat],
[long,lat]
]
]
},
我尝试使用geo_shape和geo_point进行的所有映射都没有显示在Kibana中,也没有显示在Kibana中,但是没有数据。将其映射到多个文件的最佳方法是什么? (如果没有好的方法,我的下一个想法是,如果我无法使用所有坐标,则为每个文件创建一个中心点。也许采用第一个长而纬度的数组,并为每个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并为文件建立索引时,遇到了映射器解析器异常。
最佳答案
您需要做的是创建自己的包含 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))
关于python - 映射地理多边形Elastic Search/Kibana 5.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43418311/