1.es通过curl 命令行工具实用命令3
精确匹配查询
curl -u elastic:elastic -k -XGET 192.168.1.1:9200/pro_002/_search -H 'Content-Type: application/json' -d '
{
"query": {
"term": {
"name": "pro_002"
}
}
}'
{
"took":5,
"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"
}
}
]
}
}
27.范围查询
curl -u elastic:elastic -k -XGET 192.168.1.1:9200/pro_002/_search -H 'Content-Type: application/json' -d '
{
"query": {
"range": {
"id": {
"gte": 0,
"lte": 10
}
}
}
}'
{
"took":1082,
"timed_out":false,
"_shards":{
"total":1,
"successful":1,
"skipped":0,
"failed":0
},
"hits":{
"total":{
"value":1,
"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"
}
}
]
}
}
28.must查询指定条件的索引
查询name='pro_002'的索引
curl -u elastic:elastic -k -XGET 192.168.1.1:9200/pro_002/_search -H 'Content-Type: application/json' -d '
{
"query": {
"bool": {
"must": [
{ "match": { "name": "pro_002" }}
]
}
}
}'
{
"took":6,
"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":"3",
"name":"pro_002",
"city":"深圳",
"course":"mysql",
"teacher":"粉缇",
"pxdate":"20250312"
}
}
]
}
}
29.should 查询指定条件的记录
Name='pro_002' 或者 id=3
curl -u elastic:elastic -k -XGET 192.168.1.1:9200/pro_002/_search -H 'Content-Type: application/json' -d '
{
"query": {
"bool": {
"should": [
{ "match": { "name": "pro_002" }},
{ "match": { "id":"3"} }
],
"minimum_should_match": 1
}
}
}'
{
"took":6,
"timed_out":false,
"_shards":{
"total":1,
"successful":1,
"skipped":0,
"failed":0
},
"hits":{
"total":{
"value":1,
"relation":"eq"
},
"max_score":1.3862942,
"hits":[
{
"_index":"pro_002",
"_type":"_doc",
"_id":"2",
"_score":1.3862942,
"_source":{
"id":"3",
"name":"pro_002",
"city":"深圳",
"course":"mysql",
"teacher":"粉缇",
"pxdate":"20250312"
}
}
]
}
}