弹性搜索 - 从not_analyzed转换为分析 [英] Elasticsearch - change field from not_analyzed to analyzed
问题描述
是否可以将现有字段的属性从 not_analyzed
修改为分析
?
Is it possible to modify property of an existing field from not_analyzed
to analyzed
?
如果没有,我可以做什么来保存我的所有文件?
If not, what can I do in order to keep all my documents in store ?
我无法删除映射(因为所有的文档
I cannot delete mappings (because then all documents will be gone) and I need that old field as analyzed.
推荐答案
您不能修改现有的字段,但是您也可以创建另一个字段或添加一个子字段到您的 not_analyzed
字段。
You cannot modify an existing field, however, you can either create another field or add a sub-field to your not_analyzed
field.
我将要处理后一种解决方案。首先,在现有的字段中添加一个新的子字段,如下所示:
I'm going for the latter solution. So first, add a new sub-field to your existing field, like this:
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
)
Above, we've added the sub-field called your_field.sub
(which is analyzed) to the existing your_field
(which is not_analyzed
)
接下来,我们需要填写新的子字段。如果您运行的是最新的ES 2.3,您可以使用强大的 Reindex API
Next, we'll need to populate that new sub-field. If you're running the latest ES 2.3, you can use the powerful 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配置即可重新建立数据索引,以填充新的子字段
Otherwise, you can simply use the following Logstash configuration which will re-index your data in order to populate the new sub-field
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]}"
}
}
这篇关于弹性搜索 - 从not_analyzed转换为分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!