【es】curl命令行工具实用命令2

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"
                }
            }
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值