//curl命令http请求方式
curl -X PUT "http://10.20.1.1/elastic" \
-H 'Content-Type: application/json;charset=utf-8' \
-u elastic:iie123456
-d @mapping.json
创建或更新资源:PUT(替换)、POST(创建)
删除资源:DELETE
查看资源:GET、HEAD(只返回http头部信息,不返回正文内容)
1、新建索引
curl -XPUT -H 'Content-Type: application/json' -u 'elastic:111111' 'http://127.0.0.1:9200/estest' -d@test.json
其中test.json是这样的
{ "mappings": { "properties": { "title": { "type": "text" }, "content": { "type": "text" }, "date": { "type": "date" } } } }
2、删除索引
curl -XDELETE -u 'elastic:111111' 'http://$HOSTNAME:9200/estest*'
3、查看单个索引信息
curl -XGET -u 'elastic:111111' 'http://127.0.0.1:9200/_cat/shards/estest?v'
4、查看集群所有索引信息
curl -XGET -u 'elastic:111111' 'http://127.0.0.1:9200/_cat/indices?v'
5、统计索引名包含estest的数量
curl -XGET -u 'elastic:111111' 'http://127.0.0.1:9200/_cat/indices' |grep 'estest'|wc -l
6、统计索引名包含estest,对第三列进行排序
curl -XGET -u 'elastic:111111' 'http://127.0.0.1:9200/_cat/indices' |grep 'estest'|sort -k 3
7、查看es集群健康状况
curl -XGET -u 'elastic:111111' 'http://127.0.0.1:9200/_cat/health?v'
8、es查看node节点
curl -u 'elastic:111111' 127.0.0.1:9200/_cat/nodes|wc -l
8、es用api创建用户
curl -X PUT -H 'Content-Type: application/json' -u 'elastic:111111' --url 'http://127.0.0.1:9200/_xpack/security/user/username -d ' { "password": "iie123$%^", "roles": ["username_role"] } '
9、给用户赋权
curl -X PUT -H 'Content-Type: application/json' -u 'elastic:111111' --url 'http://127.0.0.1:9200/_xpack/security/role/username_role -d ' { "cluster":[],"indices":[{"names":["es_index_name"],"privileges":["read"]}]}'
10、修改用户密码
curl -X PUT -H 'Content-Type: application/json' -u 'elastic:111111' --url 'http://127.0.0.1:9200/_xpack/security/user/username/_password -d ' { "password": "iie123$%^"} '