1 查询有多少索引以及他们的状态
curl -XGET http://127.0.0.1:9200/_cat/indices?v
2 创建索引indexxxx
curl -XPUT http://127.0.0.1:9200/indexxxx
3 查询索引indexxxx信息
curl -XGET http://127.0.0.1:9200/indexxxx
4 创建文档(一条数据),也可以覆盖之前已经存在的数据
curl -H'Content-Type: application/json' -XPOST http://127.0.0.1:9200/indexxxx/_doc/1001 -d '
{
"name":"hhhhh",
"sex":"man"
}'
5 使用索引查询文档
curl -XGET 127.0.0.1:9200/indexxxx/_doc/1001
6 修改实体的某一项参数
curl -XPOST -H 'Content-Type:application/json' 127.0.0.1:9200/indexxxx/_update/1002 -d '
{
"doc" :
{
"agee" : 25
}
}'
7 删除一个文本
curl -XDELETE 127.0.0.1:9200/indexxxx/_doc/1003
8 条件查询
curl -H'Content-Type:application/json' -XPOST 127.0.0.1:9200/indexxxx/_search -d '
{
"query" :
{
"match" :
{
"name" : "zhanggggg"
}
}
} '
9 查询所有的数据
curl -XPOST -H'Content-Type:application/json' 127.0.0.1:9200/indexxxx/_search -d '
{
"query":
{
"match_all":{}
}
},
10 分页查询
curl -XPOST -H'Content-Type:application/json' 127.0.0.1:9200/indexxxx/_search -d '
{
"query":
{
"match_all":{}
},
"from":2,
"to":2,
}'
11 过滤输出
curl -XPOST -H'Content-Type:application/json' 127.0.0.1:9200/indexxxx/_search -d '
{
"query":
{
"match_all":{}
},
"from":2,
"to":2,
"_source":["age"]
}'
12 多条件查询
curl -XPOST -H'Content-Type:application/json' 127.0.0.1:9200/indexxxx/_search -d '
{
"query":
{
"bool":
{
"must":
[
{
"match":
{
"age":22
}
},
{
"match":
{
"name":"huaiiiii"
}
}
]
}
}
}'
curl -XPOST -H'Content-Type:application/json' 127.0.0.1:9200/indexxxx/_search -d '
{
"query":
{
"bool":
{
"should":
[
{
"match":
{
"name":"leeeee"
}
},
{
"match":
{
"age":22
}
}
]
}
}
}'
13 范围查询
curl -XPOST -H'Content-Type:application/json' 127.0.0.1:9200/indexxxx/_search -d '
{
"query":
{
"bool":
{
"should":
[
{
"match":
{
"name":"leeeee"
}
},
{
"match":
{
"age":22
}
}
],
"filter":
{
"range":
{
"age":
{
"gt":20
}
}
}
}
}
}'
14 完全匹配–match_phrase
curl -XPOST -H'Content-Type:application/json' 127.0.0.1:9200/indexxxx/_search -d '
{
"query":
{
"bool" :
{
"must":
{
"match_phrase":
{
"name":"李"
}
}
}
}
}'
15 查询结果高亮显示
curl -XPOST -H'Content-Type:application/json' 127.0.0.1:9200/indexxxx/_search -d '
{
"query":
{
"bool" :
{
"must":
{
"match_phrase":
{
"name":"李"
}
}
}
},
"highlight":
{
"fields":
{
"name":{}
}
}
}'
16 聚合操作
curl -XPOST -H"Content-Type:application/json" 127.0.0.1:9200/iiii/_search -d '
{
"aggs":
{
"nnn_grp":
{
"terms":
{
"field":"num"
}
}
},
"size":0
}'
17 求平均值
curl -XPOST -H"Content-Type:application/json" 127.0.0.1:9200/iiii/_search -d '
{
"aggs":
{
"nnn_grp":
{
"agv":
{
"field":"num"
}
}
},
"size":0
}'
18 通过账号密码登录或者访问
curl -k --user "name:passwd" https://xx.xx.xx.xx:9200
19 基于field的联合查询语句
curl -XPOST -H"Content-Type:application/json" 127.0.0.1:9200/iiii/_search -d '
{
"query": {
"bool": {
"filter": [
{
"range": {
"key11.key12.field1": {
"gte": "20240517000000",
"lte": "20240517235959"
}
}
},
{
"term": {
"key21.field2": "xxxxxxxx"
}
},
{
"term": {
"key31.key32.field3" : "yyyyyyyyyyy"
}
},
{
"query_string": {
"fields": [
"key41.key42.field4"
],
"query": "(/.*zzzzzzz.*/)"
}
}
]
}
},
"track_total_hits": true,
"from": 0,
"size": 10
}'
20 查看索引indexxxx的mapping信息
curl -XGET http://127.0.0.1:9200/indexxxx/_mapping
21 查看索引indexxxx有多少条数据
curl -XGET http://127.0.0.1:9200/indexxxx/_count
22 查看集群节点情况
curl -XGET http://127.0.0.1:9200/_cat/nodes
23 查看集群各个节点状态
curl -XGET http://127.0.0.1:9200/_nodes/stats
24 查看集群分片情况
curl -XGET http://127.0.0.1:9200/_cat/shards?v
发表回复