其实也就是简单的创建修改,并不是多大的进步~不想和之前的写一起.
简单创建
请求方式
PUT:http://localhost:8101/xianxian/
索引信息

我运行了三个节点.可以看到我的默认分片数1.副本数是1.至于这个是配置文件中的默认是设置还是跟节点数有关的默认设置没有去考证.可以自行去了解.
查看索引
查看全部
请求方式
GET:http://localhost:8101/xianxian/
返回结果
{
"xianxian":{
"aliases":{
},
"mappings":{
},
"settings":{
"index":{
"creation_date":"1559490528771",
"number_of_shards":"1",
"number_of_replicas":"2",
"uuid":"NhiHDjw3SuSeUWwUcZmboQ",
"version":{
"created":"7010099"
},
"provided_name":"xianxian"
}
}
}
}查看Mappings
请求方式
GET:http://localhost:8101/xianxian/_mappings/
查看settings的参数同理
返回结果
{
"xianxian1":{
"mappings":{
}
}
}查看Alias
请求方式
GET:http://localhost:8101/xianxian/__alias/*/
查询结果
{
"_index":"xianxian",
"_type":"__alias",
"_id":"*",
"found":false
}修改索引
修改注意
索引修改应关闭再修改后开启.
关闭索引
请求方式
POST:http://localhost:8101/xianxian/_close/
返回结果
{
"acknowledged":true
}开启索引
请求方式
POST:http://localhost:8101/xianxian/_open/
返回结果
{
"acknowledged": true,
"shards_acknowledged": true
}修改副本
# 关闭索引
POST:http://localhost:8101/xianxian/_close/
# 修改索引
PUT:http://localhost:8101/xianxian/_settings/
#开启索引
POST:http://localhost:8101/xianxian/_open/请求参数
{
"number_of_replicas": 3
}返回结果
{
"acknowledged":true
}修改分片
# 关闭索引
POST:http://localhost:8101/xianxian/_close/
# 修改索引
PUT:http://localhost:8101/xianxian/_settings/
#开启索引
POST:http://localhost:8101/xianxian/_open/请求参数
{
"number_of_shards": 2
}返回错误
{
"error":{
"root_cause":[
{
"type":"illegal_argument_exception",
"reason":"final xianxian setting [index.number_of_shards], not updateable"
}
],
"type":"illegal_argument_exception",
"reason":"final xianxian setting [index.number_of_shards], not updateable"
},
"status":400
}错误原因
索引一旦建立,主分片数量不可改变.
添加索引属性
请求方式
PUT:http://localhost:8101/xianxian/_mappings/
请求参数
{
"properties":{
"hello_xianxian":{
"type":"integer"
}
}
}返回结果
{
"acknowledged":true
}修改索引属性
请求方式
PUT:http://localhost:8101/xianxian/_mappings/
请求参数
{
"properties":{
"hello_xianxian":{
"type":"text"
}
}
}返回错误
{
"error":{
"root_cause":[
{
"type":"illegal_argument_exception",
"reason":"mapper [hello_xianxian] of different type, current_type [integer], merged_type [text]"
}
],
"type":"illegal_argument_exception",
"reason":"mapper [hello_xianxian] of different type, current_type [integer], merged_type [text]"
},
"status":400
}错误原因
如果一个字段的类型修改以后,那么该字段的所有数据都需要重新索引.Elasticsearch底层使用的是lucene库,字段类型修改以后索引和搜索要涉及分词方式等操作,不允许修改类型在我看来是符合lucene机制的.

