es创建索引及别名更新mapping方法 elasticsearch [nested] nested object under path [XXX] is not of nested type

2024-10-09 08:08:18 浏览数 (3)

[nested] nested object under path [XXX] is not of nested type这是因为在创建索引时没有指定类型为数组,这就是一个大坑,ES官方说可以不用指定数字组类型,结果不指定的聚合结果还不一样!!!

由于Elasticsearch底层使用了lucene的原因,不支持对mapping的修改,可使用索引重建的方式,升级版本的思路来做别名映射处理。 1.创建索引 创建一个索引,这个索引的名称最好带上版本号,比如my_index_v1,my_index_v2等。 my_index_v1 PUT { "settings": { "index.mapping.total_fields.limit": 2000, "number_of_shards": 5, "number_of_replicas": 1 } "mappings": { "_doc": { ... } }

2.索引复制,使用reindex api将旧索引数据导入新索引 _reindex POST { "source": { "index": "my_index", "type": "_doc" },

"dest": { "index": "my_index_v1", "type": "_doc"

} }

3.在视图确认已经创建且复制成功,然后删除原来的索引 my_index  DELETE

4.创建同之前的索引的相同名称的别名,不删除索引而创建同名的别名会报错“an index exists with the same name as the alias” /_aliases PUT { "actions": [ { "add": { "alias": "my_index", "index": "my_index_v1" }} ] } 如果需要删除别名 /_aliases PUT { "actions": [ { "remove": { "alias": "my_index", "index": "my_index_v1" }} ] } 无缝切换 { "actions": [ { "remove": { "alias": "my_index", "index": "my_index_v1" }}, { "add": { "alias": "my_index", "index": "my_index_v2" }} ] }

5.查看别名 _alias GET

查看别名 http://IP地址:9201/_cat/aliases

0 人点赞