elasticsearch - 删除嵌套字段 Elasticsearch 映射的管道
问题描述
有一个类似于下面的 Elasticsearch 映射,我正在尝试使用重新索引 API 更新它。我已经学会了如何使用管道来执行各种操作,例如删除字段或更改类型,但是没有从嵌套类型中删除字段。例如,在descriptions
现场我将如何设置管道来删除badfield
?
{
"mappings": {
"all": {
"_all": {
"enabled": false
},
"dynamic": "strict",
"properties": {
"address": {
"type": "text"
},
"businessName": {
"type": "text"
},
"descriptions": {
"type": "nested",
"properties": {
"dateSeen": {
"type": "date",
"format": "date_time"
},
"source": {
"type": "text",
},
"value": {
"type": "text"
},
"badfield": {
"type": "text"
}
}
},
"dateAdded": {
"type": "date",
"format": "date_time||date_time_no_millis"
}
}
}
}
}
顺便说一句,使用 ES 6。
我根据评论设置了一个处理器脚本,并遇到了该字段为空的问题,即使它明显存在。
{
"processors": [{
"script": {
"source": """
if (ctx._source.descriptions != null) {
for(item in ctx._source.descriptions) {
item.remove('badfield');
}
}
"""
}
}
]
}
编辑:_source
从脚本中删除是问题,这意味着我不完全了解它的用法,但能够创建一个嵌套字段删除脚本。
解决方案
我之前回答过类似的问题。用于删除嵌套的逻辑可以移动到脚本处理器。
也许文档需要澄清嵌套用例,但如果你只是试一试,它会起作用(在 ES 7.5 上测试)如果你想更深入地了解会发生什么,我想你需要检查源代码
PUT src
{
"mappings": {
"dynamic": "strict",
"properties": {
"name": {
"type": "keyword"
},
"nestedField": {
"type": "nested",
"properties": {
"field1": {
"type": "boolean"
},
"field2": {
"type": "boolean"
}
}
}
}
}
}
PUT dst
{
"mappings": {
"dynamic": "strict",
"properties": {
"name": {
"type": "keyword"
},
"nestedField": {
"type": "nested",
"properties": {
"field2": {
"type": "boolean"
}
}
}
}
}
}
POST src/_doc
{
"name": "name1",
"nestedField": {
"field1": true,
"field2": false
}
}
POST src/_doc
{
"name": "name2",
"nestedField": {
"field1": false,
"field2": true
}
}
GET src
GET src/_search
GET dst/_search
GET dst
PUT _ingest/pipeline/test_pipeline
{
"processors": [
{
"remove": {
"field": "nestedField.field1"
}
}
]
}
POST _reindex
{
"source": {
"index": "src"
},
"dest": {
"index": "dst",
"pipeline": "test_pipeline"
}
}
GET dst/_search
GET dst
#DELETE src
#DELETE dst
推荐阅读
- docker - Rust 安装失败。命令 'rustup-init -y' 抛出错误。
- angular - 动态更改 angular2-query-builder 中的配置
- android - 点击或活动期间的Android EditText Tint Color Change
- angularjs - 具有angular-ui模态形式的angularjs
- java - 如何使用while循环将字符串值放入从用户获得的字符串数组中
- python-3.x - Python-使用字典在其他列中使用条件替换列中的行
- javascript - 如何从 FlatList 中删除一个项目,然后在 React Native 中更新该列表?
- javascript - 当我使用 js 更改类名时,css 转换不起作用
- python - 使用 Flask SQLAlchemy 为管理系统链接数据库
- javascript - 我如何克隆和擦除每一行中的一行