1、查看集群状态
curl -XGET 'localhost:9200/_cat/health?v'
|
2、创建索引
curl -XPUT 'localhost:9200/index_name?pretty'
|
index_name: 索引名
3、查看索引
curl -XGET 'localhost:9200/_cat/indices?v'
|
4、查看索引settings设置
curl -XGET "localhost:9200/index_name/_settings?pretty"
|
5、查看mapping结构
curl -XGET "localhost:9200/index_name/_mapping?pretty"
|
6、插入数据
curl -XPUT 'localhost:9200/index_name/index_type/1?pretty' -d '{"name":"wes"}'
|
index_type: 索引数据类型
7、删除索引
curl -XDELETE 'localhost:9200/index_name?pretty'
|
8、查看模板
curl -XGET 'localhost:9200/_template'
|
9、删除模板
curl -XDELETE localhost: 9200 /_template/no_analyzed
|
10、添加模板-设置副本
11、添加模板-设置不分词
curl -XPUT "http://localhost:9200/_template/no_analyzed" -d '
{
"template" : "*" ,
"mappings" : {
"_default_" : {
"dynamic_templates" : [
{
"strings" : {
"match_mapping_type" : "string" ,
"mapping" : {
"type" : "keyword"
}
}
}
]
}
}
}'
|
参考链接:https://www.elastic.co/guide/en/elasticsearch/reference/5.5/default-mapping.html
#5.x版本默认启用分词,字段的type:text,不分词表示为type:keyword:
12、添加模板-设置别名,例如heart_beat_station_real
curl -XPUT "http://localhost:9200/_template/aliases" -d '
{
"template" : "heart_beat_station_real*" ,
"aliases" : {
"a_heart_beat_station_real" : [
{ "add" : { "index" : "logs*" , "alias" : "a_heart_beat_station_real" } }
]
}
}'
|
13、添加模板-设置数据写入时间及索引warm模式
14、设置索引一次查询显示数量最大值(可以将_all改为index名)
15、reindex索引,reindex前先设置新索引的mapping
curl -XPOST 'localhost:9200/_reindex' -d '
{
"source" : {
"index" : "my_index_name"
},
"dest" : {
"index" : "my_index_name_new"
}
}'
|
16、创建仓库
bak_name: 仓库名
17、查看仓库状态
curl -XGET 'localhost:9200/_snapshot/bak_name?pretty'
|
18、删除仓库
curl -XDELETE "localhost: 9200 /_snapshot/bak_name
|
19、备份索引数据,快照名最好跟索引名保持一致
curl -XPUT "localhost:9200/_snapshot/bak_name/video" -d '
{
"indices" : "video_violation_201805,video_police_case_201805,video_treat_case_201805"
}'
|
20、查看快照名及包含的索引
curl -XGET 'localhost:9200/_snapshot/bak_name/_all'
|
21、删除快照
curl -XDELETE 'localhost:9200/_snapshot/bak_name/zhongshi-06-20'
|
1
zhongshi-06-20: 快照名
22、增加每分钟可执行的脚本次数
curl -XPUT localhost: 9200 /_cluster/settings -d '
{
"transient" : {
"script.max_compilations_per_minute" : 150
}
}'
|
或者在配置文件中修改:script.max_compilations_per_minute: 150
23、x-pack修改用户密码
curl -XPUT -u elastic '192.168.75.14:9200/_xpack/security/user/elastic/_password' -d '{
"password" : "123456"
}'
|
24、es-head插件http-basic认证登录
http: //localhost:9200/?auth_user=username&auth_password=password
|
username: 用户名
password: 用户密码
25、创建索引并设置副本为0,mapping如下
curl -XPUT "http://localhost:9200/test4/" -d '
{
"settings" : {
"number_of_replicas" : "0"
},
"mappings" : {
"test" : {
"properties" : {
"name" : {
"type" : "text" ,
"fields" : {
"keyword" : {
"type" : "keyword" ,
"ignore_above" : 256
}
}
}
}
}
}
}'
|
26、查看ES节点node信息(heap内存,sm等),直接在浏览器运行,curl运行显示信息为默认参数信息
http: //10.65.3.5:9200/_cat/nodes?v&h=ip,port,v,disk.used,hc,hp,hm,rc,rp,rm,load_1m,qcm,rcm,gc,sc,sm
|
详细参数参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-nodes.html
27、动态设置副本为0
28、mapping,动态匹配字段后设置类型
curl -XPUT "http://192.168.75.14:9200/_template/point-shape" -d '
{
"template" : "heart_beat_recorder*" ,
"mappings" : {
"_default_" : {
"dynamic_templates" : [
{
"integers" : {
"match" : "*point" ,
"mapping" : {
"type" : "geo_point"
}
}
},
{
"*" : {
"match" : "*shape" ,
"mapping" : {
"type" : "geo_shape"
}
}
}
]
}
}
}'
|
创建模板,索引heart_beat_recorder*动态匹配以point或shape结尾的字段,并设置其类型
29、添加别名
30、添加别名模板
31、添加更改时间类型模板(long_or_text处信息相当于备注)