[doda@host166 shangeshishi]$ curl -u elastic:123456 http://172.21.72.166:9200/_cat
=^.^=
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates
此命令常用查看索引信息,示例:
[doda@host166 shangeshishi]$ curl -u elastic:123456 http://172.21.72.166:9200/_cat/indices
green open ed3_label_ext0_es_20200719 FjSjSi6BRR2_TSNIyffrnw 5 0 10000 0 9.8mb 9.8mb
green open api_info_es_20200725 fyiYoZ6qQFCxTlh0p27T9g 5 0 5 0 30.5kb 30.5kb
2.1查询设置集群状态
curl -XGET -u elastic:123456 http://172.21.72.166:9200/_cluster/health?pretty=true
pretty=true表示格式化输出
level=indices 表示显示索引状态
level=shards 表示显示分片信息
2.2显示集群系统信息,包括CPU JVM等等
curl -XGET -u elastic:123456 http://172.21.72.166:9200/_cluster/stats?pretty=true
2.3集群的详细信息。包括节点、分片等。
curl -XGET -u elastic:123456 http://172.21.72.166:9200/_cluster/state?pretty=true
2.4获取集群堆积的任务
curl -XGET -u elastic:123456 http://172.21.72.166:9200/_cluster/pending_tasks?pretty=true
2.5修改集群配置
curl -XGET -u elastic:123456 http://172.21.72.166:9200/_cluster/settings -d '{ "persistent" : { "discovery.zen.minimum_master_nodes" : 2 } }' transient:表示临时的 persistent:表示永久的 2.6关闭集群 关闭指定192.168.1.1节点 curl -XPOST 'http://172.21.72.166:9200/_cluster/nodes/_local/_shutdown' 关闭主节点 curl -XPOST 'http://172.21.72.166:9200/_cluster/nodes/_master/_shutdown' 关闭整个集群(delay=10s表示延迟10秒关闭) curl -XPOST 'http://172.21.72.166:9200/_shutdown?delay=10s' curl -XPOST 'http://172.21.72.166:9200/_cluster/nodes/_shutdown' curl -XPOST 'http://172.21.72.166:9200/_cluster/nodes/_all/_shutdown'3.nods系统 *** 作
略,用到再说
4.索引类 *** 作 4.1创建索[doda@host166 shangeshishi]$ curl -H "Content-Type: application/json" -u elastic:123456 -XPUT 'http://172.21.72.166:9200/test_user_20211020' -d '{
"settings": {
"index.refresh_interval": -1,
"index.translog.durability": "async",
"index.mapping.total_fields.limit": "1000",
"index.translog.flush_threshold_size": "2048m",
"index.codec": "best_compression",
"index.number_of_replicas": 0,
"index.number_of_shards": "8",
"index.translog.sync_interval": "60s"
},
"mappings": {
"test_user_20211020": {
"properties": {
"id": {
"type": "long"
},
" name": {
"type": "keyword"
},
" age": {
"type": "long"
},
"address": {
"type": "keyword"
}
}
}
}
}'
获取某个索引
curl -XGET -u http://172.21.72.166:9200/test_user_20211020?pretty=true
获取索引的mapping信息
curl -XGET -u elastic:123456 http://172.21.72.166:9200/test_user_20211020/_mapping?pretty=true
返回结果
{
"test_user_20211020" : {
"mappings" : {
"test_user_20211020" : {
"properties" : {
" age" : {
"type" : "long"
},
" name" : {
"type" : "keyword"
},
"address" : {
"type" : "keyword"
},
"id" : {
"type" : "long"
}
}
}
}
}
}
[doda@host166 shangeshishi]$ curl -XPUT -H "Content-Type: application/json" -u elastic:123456 http://172.21.72.166:9200/test_user_20211020/test_user_20211020/1?pretty=true -d '{"name":"john","age":28,"address":"广州会江"}'
{
"_index" : "test_user_20211020",
"_type" : "test_user_20211020",
"_id" : "1",
"_version" : 2,
"result" : "updated",
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1
}
[doda@host166 shangeshishi]$ curl -XGET -u elastic:123456 http://172.21.72.166:9200/test_user_20211020/test_user_20211020/1?pretty=true
{
"_index" : "test_user_20211020",
"_type" : "test_user_20211020",
"_id" : "1",
"_version" : 2,
"_seq_no" : 1,
"_primary_term" : 1,
"found" : true,
"_source" : {
"name" : "john",
"age" : 28,
"address" : "广州会江"
}
}
根据字段精确匹配
[doda@host166 shangeshishi]$curl -XGET -H "Content-Type: application/json" -u elastic:123456 http://172.21.72.166:9200/test_user_20211020/test_user_20211020/_search?pretty=true -d '{
"query": {
"match": {
"address": "广州会江"
}
}
}'
返回结果
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 8,
"successful" : 8,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.2876821,
"hits" : [
{
"_index" : "test_user_20211020",
"_type" : "test_user_20211020",
"_id" : "1",
"_score" : 0.2876821,
"_source" : {
"name" : "john",
"age" : 28,
"address" : "广州会江"
}
}
]
}
}
精查询AND条件查询
[doda@host166 shangeshishi]$curl -XGET -H "Content-Type: application/json" -u elastic:123456 http://172.21.72.166:9200/test_user_20211020/test_user_20211020/_search?pretty=true -d '{
"query": {
"bool": {
"must": [{
"match": {
"address": "广州会江"
}
},
{
"match": {
"age": "28"
}
}
]
}
},
"size": 5,
"from": 0
}'
返回结果:
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 8,
"successful" : 8,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.287682,
"hits" : [
{
"_index" : "test_user_20211020",
"_type" : "test_user_20211020",
"_id" : "1",
"_score" : 1.287682,
"_source" : {
"name" : "john",
"age" : 28,
"address" : "广州会江"
}
}
]
}
}
范围查询
[doda@host166 shangeshishi]$curl -XGET -H "Content-Type: application/json" -u elastic:123456 http://172.21.72.166:9200/test_user_20211020/test_user_20211020/_search?pretty=true -d '{
"query": {
"bool": {
"must": {
"match": {
"address": "广州会江"
}
},
"filter": {
"range": {
"age": {
"gt": 20,
"lte": 28
}
}
}
}
}
}'
符合含义
gte :大于或等于
gt:大于
lte :小于或等于
lt :小于
模糊查询(wildcard)
[doda@host166 shangeshishi]$ curl -XGET -H "Content-Type: application/json" -u elastic:123456 http://172.21.72.166:9200/test_user_20211020/test_user_20211020/_search?pretty=true -d '{
"query": {
"wildcard": {
"address": "*广州*"
}
}
}'
[doda@host166 shangeshishi]$curl -XPOST -H "Content-Type: application/json" -u elastic:123456 http://172.21.72.166:9200/test_user_20211020/test_user_20211020/_delete_by_query?pretty=true -d '{
"query": {
"match": {
"address": "广州会江"
}
}
}'
[doda@host166 shangeshishi]$ curl -XDELETE -H "Content-Type: application/json" -u elastic:123456 http://172.21.72.166:9200/test_user_20211020
{"acknowledged":true}
[doda@host166 shangeshishi]$curl -XPOST -H "Content-Type: application/json" -u elastic:123456 http://172.21.72.166:9200/test_user_20211020/test_user_20211020/_aliases?pretty=true -d '{
"actions": [{
"add": {
"index": "test_user_20211020",
"alias": "test_user_20211020_alias"
}
}]
}'
[doda@host166 shangeshishi]$curl -XPOST -H "Content-Type: application/json" -u elastic:123456 http://172.21.72.166:9200/test_user_20211020/test_user_20211020/_aliases?pretty=true -d '{
"actions": [{
"remove": {
"alias": "test_user_20211020_alias",
"index": "test_user_20211020"
}
}]
}'
[doda@host166 shangeshishi]$ curl -XPOST -H "Content-Type: application/json" -u elastic:123456 http://172.21.72.166:9200/test_user_20211020/test_user_20211020?pretty=true -d '{
"mappings": {
"properties": {
"age": {
"type": "text"
}
}
}
}'
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)