问题描述
我有以下类型的文件.
{
"_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
]
]
}
}
下面是映射:
{
"example1": {
"mappings": {
"doc": {
"properties": {
"locations": {
"type": "geo_point"
},
"postDate": {
"type": "date"
},
"status": {
"type": "long"
},
"user": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
我可以使用以下查询添加多个位置.
I can add multiple locations using below query.
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 {
But not able remove array objects from locations. I have tried below query but working. POST example1/doc/3/_update {
"script" :
{
"lang":"painless",
"inline":"ctx._source.locations.remove(params.tag)",
"params":{
"tag":[-74.00,41.12121]
}
}
}
请让我知道我在哪里做错了.我正在使用弹性版本5.5.2
Kindly let me know where i am doing wrong here. I am using elastic version 5.5.2
推荐答案
与add()
不同,remove()
采用元素的索引并将其删除.
Unlike add()
, remove()
takes the index of the element and remove it.
您的ctx._source.locations
轻松地是ArrayList
.它具有List
的 remove()
方法:
Your ctx._source.locations
in painless is an ArrayList
. It has List
's remove()
method:
删除此列表中指定位置的元素(可选操作). ...
Removes the element at the specified position in this list (optional operation). ...
请参见无痛API-列表,用于其他方法.
See Painless API - List for other methods.
例如参见此答案代码.
这篇关于从ElasticSearch中的数组中删除元素/对象,然后进行匹配查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!