是否可以将现有字段的属性从 not_analyzed
修改为 analyzed
?
如果没有,我该怎么做才能保存我所有的文件?
我无法删除映射(因为那样所有文档都将消失)并且我需要分析过的旧字段。
最佳答案
您不能修改现有字段,但是,您可以创建另一个字段或 add a sub-field到您的 not_analyzed
字段。
我选择后一种解决方案。所以首先,向现有字段添加一个新的子字段,如下所示:
curl -XPUT localhost:9200/index/_mapping/type -d '{
"properties": {
"your_field": {
"type": "string",
"index": "not_analyzed",
"fields": {
"sub": {
"type": "string"
}
}
}
}
}'
上面,我们已经将名为 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"
}
}'
否则,您可以简单地使用以下 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]}"
}
}
关于Elasticsearch - 将字段从 not_analyzed 更改为 analyzed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36445141/