我在尝试从Elasticsearch的数组中删除元素/对象时遇到了问题。
这是索引的映射:
使用下面的查询,我可以添加多个位置。
但是我无法从位置中删除数组对象。我尝试了下面的查询,但它没有起作用。
请告诉我在这里哪里出错了。我正在使用弹性版本5.5.2。
这是索引的映射:
{
"example1": {
"mappings": {
"doc": {
"properties": {
"locations": {
"type": "geo_point"
},
"postDate": {
"type": "date"
},
"status": {
"type": "long"
},
"user": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
这是一个示例文档。
{
"_index": "example1",
"_type": "doc",
"_id": "8036",
"_score": 1,
"_source": {
"user": "kimchy8036",
"postDate": "2009-11-15T13:12:00",
"locations": [
[
72.79887719999999,
21.193036000000003
],
[
-1.8262150000000001,
51.178881999999994
]
]
}
}
使用下面的查询,我可以添加多个位置。
POST /example1/_update_by_query
{
"query": {
"match": {
"_id": "3"
}
},
"script": {
"lang": "painless",
"inline": "ctx._source.locations.add(params.newsupp)",
"params": {
"newsupp": [
-74.00,
41.12121
]
}
}
}
但是我无法从位置中删除数组对象。我尝试了下面的查询,但它没有起作用。
POST example1/doc/3/_update
{
"script": {
"lang": "painless",
"inline": "ctx._source.locations.remove(params.tag)",
"params": {
"tag": [
-74.00,
41.12121
]
}
}
}
请告诉我在这里哪里出错了。我正在使用弹性版本5.5.2。