是否可以将现有字段的属性修改not_analyzed为analyzed?
如果没有,我可以做些什么来保存我的所有文件?
我无法删除映射(因为那时所有文档都将消失),我需要分析旧字段.
不能修改现有字段,但是,您可以创建其他字段或子字段添加到您的not_analyzed领域.
我要采用后一种解决方案.首先,在现有字段中添加一个新的子字段,如下所示:
curl -XPUT localhost:9200/index/_mapping/type -d '{
"properties": {
"your_field": {
"type": "string",
"index": "not_analyzed",
"fields": {
"sub": {
"type": "string"
}
}
}
}
}'
Run Code Online (Sandbox Code Playgroud)
在上面,我们添加了被称为your_field.sub(被分析)的子字段到现有的your_field(这是not_analyzed)
接下来,我们需要填充新的子字段.如果您运行的是最新的ES 2.3,则可以使用功能强大的Reindex API
curl -XPUT localhost:9200/_reindex -d '{
"source": {
"index": "index"
},
"dest": {
"index": "index"
},
"script": {
"inline": "ctx._source.your_field = ctx._source.your_field"
}
}'
Run Code Online (Sandbox Code Playgroud)
否则,您只需使用以下Logstash配置,该配置将重新索引您的数据以填充新的子字段
input {
elasticsearch {
hosts => "localhost:9200"
index => "index"
docinfo => true
}
}
filter {
mutate {
remove_field => [ "@version", "@timestamp" ]
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
manage_template => false
index => "%{[@metadata][_index]}"
document_type => "%{[@metadata][_type]}"
document_id => "%{[@metadata][_id]}"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3335 次 |
| 最近记录: |