我向Elasticsearch记录了一些数据。但是我的模板效果不好,并且位置数据是动态映射的。我想用查询脚本重新索引所有数据。如何将位置数据转换为几何形状?
样本数据:
plt.plot(something)
plt.show()
{
"deviceId": "dev1",
"location": {
"type": "Point",
"coordinates": [
28.891983032226562,
41.02446333535115
]
}
}
字段映射为type
,而text
映射为coordinates
。
float
索引放置映射请求:
test3
我的重新编制索引脚本(已编辑):
PUT /test3
{
"mappings": {
"doc": {
"properties": {
"location": {
"type": "geo_shape",
"tree": "quadtree",
"precision": "100m"
}
}
}
}
}
Elasticsearch回复:
POST _reindex
{
"size": 1000,
"source": {
"index": "test"
, "query": {
"constant_score": {
"filter": {
"exists": {
"field": "location"
}
}
}
}
},
"dest": {
"index": "test3"
},
"script":{
"inline": "if(ctx._source.location.size()>1) {ctx._source.templocation=ctx._source.remove('location'); ctx._source['location.type'] = 'Point'; ctx._source['location.coordinates'] = ctx._source.templocation; ctx._source.remove('templocation'); } "
}
}
{
"took": 172,
"timed_out": false,
"total": 2,
"updated": 0,
"created": 0,
"deleted": 0,
"batches": 1,
"version_conflicts": 0,
"noops": 0,
"retries": {
"bulk": 0,
"search": 0
},
"throttled_millis": 0,
"requests_per_second": -1,
"throttled_until_millis": 0,
"failures": [
{
"index": "test3",
"type": "data",
"id": "AWXsdV-z29dKQeP_vT68",
"cause": {
"type": "illegal_argument_exception",
"reason": "[location] is defined as an object in mapping [data] but this name is already used for a field in other types"
},
"status": 400
},
{
"index": "test3",
"type": "data",
"id": "AWXsdVAP29dKQeP_vT67",
"cause": {
"type": "illegal_argument_exception",
"reason": "[location] is defined as an object in mapping [data] but this name is already used for a field in other types"
},
"status": 400
}
]
}
的结果
curl -XGET localhost:9200/test3
答案 0 :(得分:0)
脚本中有错字,应删除一个悬空的方括号
"inline": "... ctx._source['location.coordinates'] = ctx._source.templocation]; ctx._source.remove('templocation'); } "
^
|
remove this