我已插入新字段wiki_collection
并使用以下内容将其值设置为true
:
POST /pibtest1/_update_by_query
{
"script": {
"inline": "ctx._source.wiki_collection=true"
},
"query": {
"match": {
"url":"http%3A%2F%2Fwww.searchtechnologies.com%2Fbundles%2Fmodernizr%3Fv%3D7-yR01kdRVQ7W1RQzMBVKYLDhCt0itEATWHixfzE8Os1"
}
}
}
但是现在我要删除这个字段。我想这样做:
POST /pibtest1/_update
{
"script" : "ctx._source.remove(\"wiki_collection\")"
}
但我收到的错误是:
{
"error": {
"root_cause": [
{
"type": "invalid_type_name_exception",
"reason": "Document mapping type name can't start with '_'"
}
],
"type": "invalid_type_name_exception",
"reason": "Document mapping type name can't start with '_'"
},
"status": 400
}
还有其他方法可以删除elasticsearch中的字段吗?
编辑:我已按查询更新:
POST /pibtest1/_update_by_query
{
"script": {
"inline": "ctx._source.remove(\"wiki_collection\")"
},
"query": {
"match": {
"url": "http://www.searchtechnologies.com/bundles/modernizr?v=7-yR01kdRVQ7W1RQzMBVKYLDhCt0itEATWHixfzE8Os1"
}
}
}
但现在我收到了一个名为" remove =' wiki_collection'"在我的文档中看起来像这样:http://i.stack.imgur.com/QvxIa.png 我想从我的文档中删除/删除此wiki_collection字段。
答案 0 :(得分:2)
您的更新错误。它应该是(您指定完整路径 - 索引/类型/ ID ):
POST /pibtest1/test/234/_update
{
"script": {
"inline": "ctx._source.remove(\"wiki_collection\")"
}
}
或者您使用相同的 _update_by_query
:
POST /pibtest1/_update_by_query
{
"script": {
"inline": "ctx._source.remove(\"wiki_collection\")"
},
"query": {
"match": {
"url": "whatever"
}
}
}