1、创建索一个没有字段的索引
#创建索引(并且指定分片数量)
PUT my_index1
{
"settings": {
"number_of_shards": 2,
"number_of_replicas": 2
}
}
2、创建索一个有字段的索引
#创建索引(并且指定分片数量)
PUT myindex2
{
"settings": {
"number_of_shards": 5,
"number_of_replicas": 0
},
"mappings": {
"properties": {
"id": {
"type": "long"
},
"name": {
"type": "text"
},
"type": {
"type": "keyword"
},
"score": {
"type": "double"
}
}
}
}
3、修改分片副本
#创建索引(并且指定分片数量)
PUT my_index1/_settings
{
"index": {
"number_of_replicas": "4"
}
}
4、新增Mapping映射(新增字段)
POST /my_index2/_mapping
{
"properties": {
"phone":{
"type": "keyword"
}
}
}
注:只能新增字段,不能删除字段,一旦设置type类型,不可更改。
为什么不能修改一个字段的type?原因是一个字段的类型修改以后,那么该字段的所有数据都需要重新索引。

本文介绍如何在Elasticsearch中创建无字段和带字段的索引,包括设置分片数量、修改副本数量及新增字段映射的方法。同时解释了为何不能修改字段类型的原因,涉及到Lucene底层实现及索引重建的问题。
最低0.47元/天 解锁文章
702

被折叠的 条评论
为什么被折叠?



