映射地理多边形弹性 Search/Kibana 5.3
mapping geo polygon Elastic Search/Kibana 5.3
我有 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 数组并将其作为每个 geo_point 的中心点41=] 文件。也不知道该怎么做)
这是我在不更改任何内容的情况下建立索引时来自 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\"}}}}}"
我正在通过循环并发送 post 请求来索引我的文件:
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))
我有 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 数组并将其作为每个 geo_point 的中心点41=] 文件。也不知道该怎么做)
这是我在不更改任何内容的情况下建立索引时来自 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\"}}}}}"
我正在通过循环并发送 post 请求来索引我的文件:
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))