Elasticsearch - 将字段从 not_analyzed 更改为 analyzed

标签 elasticsearch

是否可以将现有字段的属性从 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/

相关文章:

mysql - 存储和索引 1M+ XML 文档的最佳实践?

elasticsearch - 嵌套文档上的ElasticSearch查询过滤器

elasticsearch - 升级Elasticsearch主版本

java - 模仿 Elasticsearch MatchQuery

ruby-on-rails - 可以在elasticsearch-rails中使用copy_to吗?

elasticsearch - ELK中的日期时间解析

elasticsearch - 在ElasticSearch中是否可以具有与子项相同类型的_parent映射?

php - 具有术语和方面的弹性

java - 自动化 mongodb 和 elasticsearch 同步

elasticsearch - ElasticSearch 5.2用空格分隔句子