赞
踩
GET /_cat/health?v
前两个是时间戳,其余含义如下:
1. cluster , 集群名称
2. status, 集群状态 green代表健康;yellow代表分配了所有主分片,但至少缺少一个副本,此时集群数据仍旧完整;red代表部分主分片不可用,可能已经丢失数据。
3. node.total, 代表在线的节点总数量
4. node.data, 代表在线的数据节点的数量
5. shards, active_shards 存活的分片数量
6. pri,active_primary_shards 存活的主分片数量 正常情况下 shards的数量是pri的两倍。
7. relo, relocating_shards 迁移中的分片数量,正常情况为 0
8. init, initializing_shards 初始化中的分片数量 正常情况为 0
9. unassign, unassigned_shards 未分配的分片 正常情况为 0
10. pending_tasks, 准备中的任务,任务指迁移分片等 正常情况为 0
11. max_task_wait_time, 任务最长等待时间
12. active_shards_percent, 正常分片百分比 正常情况为 100%
参考文章: https://blog.csdn.net/weixin_44723434/article/details/90452083
GET /_cat/indices?v
含义:
1. health 索引健康状态
2. status 索引的开启状态
3. index 索引名称
4. uuid 索引uuid
5. pri 索引主分片数
6. rep 索引副本分片数量
7. docs.count 索引中文档总数
8. docs.deleted 索引中删除状态的文档
9. store.size 主分片+副本分分片的大小
10. pri.store.size 主分片的大小
参考文章: https://blog.csdn.net/qq_28988969/article/details/105079476
GET /_cat/nodes?v
返回字段 | 含义 |
---|---|
ip | ip |
heap.percent | 堆内存占用百分比 |
ram.percent | 内存占用百分比 |
cpu | CPU占用百分比 |
load_1m | 1分钟的系统负载 |
load_5m | 5分钟的系统负载 |
load_15m | 15分钟的系统负载 |
node.role | node节点的角色 |
master | 是否是master节点 |
name | 节点名称 |
参考文章: https://blog.csdn.net/qq_28988969/article/details/105079476
PUT /test01
DELETE /test01
说明: 如果之前没建过 index 或者 type,es 会自动创建。
PUT /movie_index/movie/1 { "id":1, "name":"operation red sea", "doubanScore":8.5, "actorList":[ {"id":1,"name":"zhang yi"}, {"id":2,"name":"hai qing"}, {"id":3,"name":"zhang han yu"} ] } PUT /movie_index/movie/2 { "id":2, "name":"operation meigong river", "doubanScore":8.0, "actorList":[ {"id":3,"name":"zhang han yu"} ] } PUT /movie_index/movie/3 { "id":3, "name":"incident red sea", "doubanScore":5.0, "actorList":[ {"id":4,"name":"zhang chen"} ] }
GET /movie_index/movie/_search
GET /movie_index/movie/1
说明: 修改和新增没有区别,是做一个覆盖操作
PUT /movie_index/movie/3
{
"id":"3",
"name":"incident red sea",
"doubanScore":"8.0",
"actorList":[
{"id":"1","name":"zhang chen"}
]
}
POST /movie_index/movie/3/_update
{
"doc": {
"doubanScore":"8.1"
}
}
DELETE /movie_index/movie/3
GET /movie_index/movie/_search
{
"query": {
"match_all": {}
}
}
GET /movie_index/movie/_search
{
"query": {
"match": {
"name": "sea"
}
}
}
GET /movie_index/movie/_search
{
"query": {
"match": {
"actorList.name": "zhang"
}
}
}
说明: 按照短语查询是指匹配某个 field 的整个内容, 不再利用分词技术
GET /movie_index/movie/_search
{
"query": {
"match_phrase": {
"name": "operation red"
}
}
}
对比:
### 使用此条查询会把包含 operation 或者 red 的全部查找出来
GET /movie_index/movie/_search
{
"query": {
"match": {
"name": "operation red"
}
}
}
说明: 校正匹配分词,当一个单词都无法准确匹配,es 通过一种算法对非常接近的单词也给与一定的评分,能够查询出来,但是消耗更多的性能。
GET /movie_index/movie/_search
{
"query": {
"fuzzy": {
"name": "red"
}
}
}
GET /movie_index/movie/_search
{
"query": {
"match": {
"name": "red"
}
},
"post_filter": {
"term": {
"actorList.id": "3"
}
}
}
GET movie_index/movie/_search { "query": { "bool": { "filter": [ {"term": {"actorList.id": 3} }, { "term": {"actorList.id": 1} } ], "must": {"match": { "name": "zhang" }} } } }
GET movie_index/movie/_search
{
"query": {
"bool": {
"filter": {
"range": {
"doubanScore": {
"gt": 5,
"lt": 9
}
}
}
}
}
}
GET movie_index/movie/_search
{
"query":{
"match": {"name":"red operation"}
}
,
"sort": [
{
"doubanScore": {
"order": "desc"
}
}
]
}
GET movie_index/movie/_search
{
"query": { "match_all": {} },
"from": 1,
"size": 1
}
GET movie_index/movie/_search
{
"query": { "match_all": {} },
"_source": ["name", "doubanScore"]
}
# 每个演员参演了多少部电影 (按名字进行计数)
GET movie_index/movie/_search
{
"aggs": {
"groupby_actor": {
"terms": {
"field": "actorList.name.keyword"
}
}
}
}
# 每个演员参演电影的平均分是多少,并按评分排序 GET movie_index/movie/_search { "aggs": { "groupby_actor_id": { "terms": { "field": "actorList.name.keyword" , "order": { "avg_score": "desc" } }, "aggs": { "avg_score":{ "avg": { "field": "doubanScore" } } } } } }
### 使用默认的分词器
GET movie_index/_analyze
{
"text": "我是中国人"
}
使用 IK Analysis for Elasticsearch. 下载与 ElasticSearch 的版本匹配的分词器版本.
https://github.com/medcl/elasticsearch-analysis-ik/releases
需要解压到 ES 的plugins目录下
unzip elasticsearch-analysis-ik-7.8.1.zip -d /export/servers/elasticsearch/plugins/ik
#使用 ik_smart
GET movie_index/_analyze
{
"analyzer": "ik_smart",
"text": "我是中国人"
}
# 使用ik_max_word
GET movie_index/_analyze
{
"analyzer": "ik_max_word",
"text": "我是中国人"
}
通过 Mapping 来设置和查看每个字段的数据类型.
GET movie_index/_mapping
# 7.X 语法是这样详情可参考官方文档 # https://www.elastic.co/blog/moving-from-types-to-typeless-apis-in-elasticsearch-7-0 PUT /movie_chn?include_type_name=true { "mappings": { "movie":{ "properties": { "id":{ "type": "long" }, "name":{ "type": "text" , "analyzer": "ik_smart" }, "doubanScore":{ "type": "double" }, "actorList":{ "properties": { "id":{ "type":"long" }, "name":{ "type":"keyword" } } } } } } }
PUT /movie_chn/movie/1 { "id":1, "name":"红海行动", "doubanScore":8.5, "actorList":[ {"id":1,"name":"张译"}, {"id":2,"name":"海清"}, {"id":3,"name":"张涵予"} ] } PUT /movie_chn/movie/2 { "id":2, "name":"湄公河行动", "doubanScore":8.0, "actorList":[ {"id":3,"name":"张涵予"} ] } PUT /movie_chn/movie/3 { "id":3, "name":"红海事件", "doubanScore":5.0, "actorList":[ {"id":4,"name":"张晨"} ] }
GET /movie_chn/movie/_search { "query": { "match": { "name": "红海" } } } GET /movie_chn/movie/_search { "query": { "term": { "actorList.name": "张" } } }
GET kltest-panw-traffic-taged*/_mapping
GET kltest-panw-traffic-taged*/_mapping
{
"size": 10,
"query": {
"range": {
"event.start": {
"gte": "2021/04/14 09:37:00",
"lte": "2021/04/14 09:40:00"
}
}
}
}
### 查看节点
GET _cat/nodes
# kill 查询任务
POST _tasks/_cancel?nodes=节点名称&actions=*search
# 查询正在运行的任务
GET _cat/tasks?v
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。