elasticsearch常用语句
基础操作
基础查看
1、查看集群的健康状态
curl -XGET "http://10.45.151.227:9200/_cat/health?v"
2、查看nodes
curl -u elastic:123456 -XGET 'http://10.45.186.125:9200/_cat/nodes?v'
3、查看索引
curl -XGET 'http://10.45.186.155:9200/_cat/indices?pretty'
4、创建索引
curl -XPUT 'http://10.45.186.155:9200/gwtest01?pretty' -H 'Content-Type: application/json' -d '
{
"settings": {
"number_of_shards": "36",
"number_of_replicas": "0"
}
}'
5、给索引添加一条数据
curl -XPOST 'http://10.45.186.155:9200/gwtest01/stu/1?pretty' -H 'Content-Type: application/json' -d '
{
"name":"wangfang",
"age":22,
"sex":1
}'
6、查询索引所有文档:
curl -XGET 'http://10.45.151.108:9200/test/_search?pretty' -H 'Content-Type: application/json' -d '
{
"query": {
"match_all": { }
}
}'
7、删除一个索引
curl -XDELETE 'http://10.45.186.155:9200/gwtest01?pretty'
详细查看
1、查看一个索引的settings
[elastic@gwtest156 0]$ curl -XGET 'http://10.45.186.156:9200/gwtest02/_settings?pretty'
{
"gwtest02" : {
"settings" : {
"index" : {
"creation_date" : "1634645232394",
"number_of_shards" : "5", #主分片数,默认为5,只能在建索引时设置,不能修改
"number_of_replicas" : "1", #设置索引分片副本数,默认为1,可以随时修改
"uuid" : "98xWMOHKQUaP1Rl90p7zQA",
"version" : {
"created" : "6030099"
},
"provided_name" : "gwtest02"
}
}
}
}
2、查看一个文档类型的定义mapping
[elastic@gwtest156 ~]$ curl -XGET 'http://10.45.186.156:9200/gwtest02/stu/_mapping?pretty'
{
"gwtest02" : {
"mappings" : {
"stu" : {
"properties" : {
"age" : {
"type" : "long"
},
"name" : {
"type" : "text",