【发布时间】:2016-04-06 19:13:06
【问题描述】:
是否可以将现有字段的属性从not_analyzed修改为analyzed?
如果没有,我该怎么做才能保存我的所有文件?
我无法删除映射(因为所有文档都将消失),我需要分析过的旧字段。
【问题讨论】:
-
你运行的是什么版本的 ES?
-
@Val ES 版本。 2.2.0
标签: elasticsearch
是否可以将现有字段的属性从not_analyzed修改为analyzed?
如果没有,我该怎么做才能保存我的所有文件?
我无法删除映射(因为所有文档都将消失),我需要分析过的旧字段。
【问题讨论】:
标签: elasticsearch
您不能修改现有字段,但是,您可以创建另一个字段或 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]}"
}
}
【讨论】:
https://www.elastic.co/guide/en/elasticsearch/reference/0.90/mapping-multi-field-type.html
你可以用这个...有一种叫做多字段类型映射的东西,它允许你对单个字段有多个映射,你也可以根据字段类型进行查询..
【讨论】: