您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Elasticsearch-将字段从not_analyzed更改为分析

Elasticsearch-将字段从not_analyzed更改为分析

不能修改现有字段,但是,您可以创建其他字段或子字段添加到您的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]}"
 }
}
其他 2022/1/1 18:24:25 有611人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶