1、创建索引
(1)创建索引的语法
用settings给这个索引在创建时可以添加一些设置,还有可以初始化一些type的mapping
curl -H "Content-Type:application/json" -XPUT 'http://elasticsearch02:9200/twitter?pretty' -d '
{
"settings" : {
"index" : {
"number_of_shards" : 3,
"number_of_replicas" : 2
}
},
"mappings" : {
"properties" : {
"field1" : { "type" : "text" }
}
}
}'
(2)索引创建返回消息的解释
默认情况下,索引创建命令会在每个primary shard的副本开始进行复制以后,或者是请求超时以后,返回一个响应消息,类似下面这样的。
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "twitter"
}
acknowledged表明了这个索引有没有创建成功。
shards_acknowledged表明了每个primary shard有没有足够数量的replica开始进行复制了。
有可能这两个参数会为false,但是索引依然可以创建成功。因为这些参数仅仅是表明在请求超时之前,那两个行为有没有成功,也有可能请求超时了,在超时前都没成功,但是超时后在es server端还是都执行了。
如果acknoledged是false,那么就可能是超时了,此时接受到响应消息的时候,cluster state都还没变更,没有加入新创建的index,但是也许之后还是会创建这个index。如果shards_acknowledged是false,那么可能在primary shard进行副本copy之前,就timeout了,但是此时也许index创建成功了,而且cluster state已经加入了新创建的index。
2、删除索引
curl -XDELETE 'http://elasticsearch02:9200/twitter?pretty'
3、查询索引设置信息
curl -XGET 'http://elasticsearch02:9200/twitter?pretty'
4、打开/关闭索引
curl -XPOST 'http://elasticsearch02:9200/twitter/_close?pretty'
curl -XPOST 'http://elasticsearch02:9200/twitter/_open?pretty'
c