elasticsearch 常用命令
-
常用查询语句
//创建一个索引
PUT my_index
//新增1:给创建的索引新增一个文档(指定id)
PUT my_index/_create/1
{
"name":"kevin",
"age":18
}
//新增2:给创建的索引新增一个文档(指定id
PUT my_index/_doc/3?op_type=create
{
"name":"dd",
"age":15
}
//新增3:给创建的索引新增一个文档(不指定id,自动生成)
POST my_index/_doc
{
"name":"lara",
"age":16
}
//新增4index文档(也是新增文档,如果id已经存在则会覆盖掉)
PUT my_index/_doc/2
{
"tags":["basketball","running"]
}
//查询: 获取某条数据
GET my_index/_doc/1
//更新 某条数据(1.不删除已有的其他文档,2需要包含在“doc”中)
POST my_index/_update/1
{
"doc":{
"name":"jj",
"age": 60
}
}
//删除某条数据
DELETE my_index/_doc/1
//批量查询操作索引
POST _bulk
{"index":{"_index":"test","_id":"1"}}
{"field1":"value1"}
{"delete":{"_index":"test","_id":"2"}}
{"create":{"_index":"test2","_id":3}}
{"field1":"value3"}
{"update":{"_id":"1","_index":"test"}}
{"doc":{"field2":"value2"}}
//批量在各索引读取 mget
GET _mget
{
"docs":[
{"_index":"my_index",
"_id":2
},
{
"_index":"my_index2",
"_id":3
}
]
}
//查看索引相关信息
GET movies
//查看索引文档的总数
GET movies/_count
//查看前10条文档,了解文档格式
POST movies/_search
{}
//查看indices
GET /_cat/indices/movies?v&s=index
//查看状态为绿的索引
GET /_cat/indices/movies?v&health=green
//按照文档个数排序
GET /_cat/indices?v&s=docs.count:desc
//查看具体的字段
GET /_cat/indices/.kibana*?pri&v&h=health,index,pri,rep,docs.count,mt
//每个索引消耗了多少内存
GET /_cat/indices?v&h=i,tm&s=tm:desc
2 常用运维语句
//查看集群健康状况
GET _cluster/health
//查看节点信息
GET _cat/nodes
//查看shards的信息
GET _cat/shards
3 常用启动命令
-
手动启动单个机器()
-
第一种方法:
-
修改配置
-
然后正常启动: bin/elasticsearch
-
第二种 docker启动
-
docker run --name single-es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:6.8.1
-
手动启动冷热集群
-
第一步:执行下面命令,启动hot节点
bin/elasticsearch \
-E node.name=warmnode \
-E cluster.name=geektime \
-E path.data=warm_data \
-E node.attr.my_node_type=warm \
-E cluster.initial_master_nodes=node1
-
第二步:启动集群第二个节点
bin/elasticsearch \
-E node.name=warmnode \
-E cluster.name=geektime \
-E path.data=warm_data \
-E node.attr.my_node_type=warm \
-E cluster.initial_master_nodes=node2