是否可以将现有字段的属性从 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 更改为已分析,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36445141/