不能修改现有字段,但是,您可以创建其他字段或子字段添加到您的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]}"
}
}