1.es通过curl命令行管理实用命令2
curl -u elastic:elastic -XGET "192.168.1.1:9200/pro_002/_count"
{
"count":2,
"_shards":{
"total":1,
"successful":1,
"skipped":0,
"failed":0
}
}
21.查看所有的索引
curl -u elastic:elastic -XGET 192.168.1.1:9200/pro_002/_cat/indices
{"_index":"pro_002","_type":"_cat","_id":"indices","found":false}
22.随机查找一条数据
curl -XPOST -u elastic:elastic -k -XGET 'http://192.168.1.1:9200/pro_002/_search' -H 'Content-Type: application/json' -d '
{
"query": {
"match_all": {}
},
"size": 1
}'
{
"took":6,
"timed_out":false,
"_shards":{
"total":1,
"successful":1,
"skipped":0,
"failed":0
},
"hits":{
"total":{
"value":2,
"relation":"eq"
},
"max_score":1,
"hits":[
{
"_index":"pro_002",
"_type":"_doc",
"_id":"1",
"_score":1,
"_source":{
"id":"1",
"name":"user001",
"city":"广州",
"course":"oracle",
"teacher":"xsq1",
"pxdate":"20250306"
}
}
]
}
}
23.按指定的条件查询
Match 全文检索。
curl -u elastic:elastic -k -XGET 192.168.1.1:9200/pro_002/_search -H 'Content-Type: application/json' -d '
{
"query": {
"match": {
"id": "2"
}
}
}'
{
"took":128,
"timed_out":false,
"_shards":{
"total":1,
"successful":1,
"skipped":0,
"failed":0
},
"hits":{
"total":{
"value":1,
"relation":"eq"
},
"max_score":0.6931471,
"hits":[
{
"_index":"pro_002",
"_type":"_doc",
"_id":"2",
"_score":0.6931471,
"_source":{
"id":"2",
"name":"pro_002",
"city":"广州",
"course":"oracle",
"teacher":"pro",
"pxdate":"20250311"
}
}
]
}
}
term 查询用于精确值匹配,适用于非文本字段(如数字、日期、布尔值等)。
24.查看索引的结构
curl -u elastic:elastic -k -XGET 192.168.1.1:9200/pro_002/_mapping
{
"pro_002":{
"mappings":{
"properties":{
"city":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"course":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"id":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"name":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"pxdate":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"teacher":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
}
}
}
}
}
25.查询索引分片和副本
curl -u elastic:elastic -k -XGET 192.168.1.1:9200/pro_002/_settings
{
"pro_002":{
"settings":{
"index":{
"routing":{
"allocation":{
"include":{
"_tier_preference":"data_content"
}
}
},
"number_of_shards":"1",
"provided_name":"pro_002",
"creation_date":"1741247390707",
"number_of_replicas":"0",
"uuid":"b5tobKjHTkWV5im6k7mX2w",
"version":{
"created":"7170099"
}
}
}
}
}