- 查看mapping:
1curl -XGET '127.0.0.1:9200/【your-index】/_mapping' - 为现有mapping添加新属性:
123//给tags添加 age 属性:curl -X PUT 'http://127.0.0。1:9200/【your-index】/_mapping/【your-type-if-exists】' -H 'content-type:application/json' -d '{"properties":{"tags":{"type":"object","properties":{"age":{"type":"long"}}}}}'
3. 迁移旧index的数据到新index:
1curl -X POST 'http://127.0.0.1:9200/_reindex' -H 'content-type:application/json' -d '{"source":{"index":"【your-old-index】"},"dest":{"index":"【your-new-index】"}}'
4. 删除index:
1curl -X DELETE 'http://127.0.0.1:9200/【your-index】'
分类:Elasticsearch
Elasticsearch学习笔记
1. 新增加某种字段时,需要先更新mapping信息(相当于SQL中的变更表结构)。
执行方式有,
1.1 通过PUT请求动态添加新的字段;
1.2 使用新的mapping信息,新建索引(index),再通过POST请求使用_reindex来迁移旧数据;
1.3 动态添加新字段时,如果报错(Limit of total fields [1000] in index … has been exceeded),可能是有脏数据不支持的缘故,此时重建索引(index),再迁移数据(_reindex)即可。
2. Elasticsearch 仅7.0之前的版本支持在索引(index)下建 type .
(如果把index比作 sql中的database,则 type 类比sql中的table),
原因是,在sql中,不同表里可以用相同的字段名(即使只是同名,存储内容可以不同),但在Elasticsearch中,同一字段表示同一内容,即使是在不同的type中。所以被认为比较鸡肋,在7.0版本后彻底放弃了。
【参考】