ES03-常用API

ES03-常用API

文章目录


1-参考网址


2-知识总结

  • 1)Index操作-增删改查
  • 2)DOC操作-增删改查
  • 3)query操作
  • 4)Aggregations聚合

3-高频核心操作速查表


1-L1-Index

# 动作 一句话 请求示例
1.1 创建索引 指定 mapping/settings/alias PUT /shop_v1 { "settings":{ "number_of_shards":3 }, "mappings":{ "properties":{ "title":{ "type":"text" } } }, "aliases":{ "shop":{} } }
1.2 删除索引 危险,谨慎 DELETE /shop_v1
1.3 索引是否存在 HEAD 判断 HEAD /shop_v1
1.4 关闭/打开 临时下线 POST /shop_v1/_close / _open
1.5 刷新 刷缓存可见 POST /shop_v1/_refresh
1.6 别名切换 零停机重建 POST _aliases { "actions":[ { "remove":{ "index":"shop_v1","alias":"shop" } },{ "add":{ "index":"shop_v2","alias":"shop" } } ] }

2-L1-Doc

# 动作 一句话 请求示例
2.1 新建/更新 指定 ID 幂等 PUT /shop/_doc/1001 { "title":"小米","price":4999 }
2.2 局部更新 不改其他字段 POST /shop/_update/1001 { "doc":{ "price":4899 } }
2.3 获取 拿整条 GET /shop/_doc/1001
2.4 删除 单条 DELETE /shop/_doc/1001
2.5 批量写入 一行指令一行数据 POST _bulk\n{"index":{"_index":"shop","_id":"2001"}}\n{"title":"iPhone"}\n{"delete":{"_index":"shop","_id":"2002"}}

3-L1-Query

# 动作 一句话 请求示例
3.1 match 全文分词 { "query":{ "match":{ "title":"小米手机" } } }
3.2 term 精准匹配 { "query":{ "term":{ "price":4999 } } }
3.3 range 区间 { "query":{ "range":{ "price":{ "gte":2000,"lte":5000 } } } }
3.4 bool 组合过滤 { "query":{ "bool":{ "must":[ { "match":{ "title":"小米" } } ], "filter":[ { "range":{ "price":{ "gte":3000 } } } ] } } }
3.5 match_all + 分页 全量+from/size { "query":{ "match_all":{} }, "from":0,"size":20 }

4-L1-Aggregations

# 动作 一句话 请求示例
4.1 avg/max/min 指标 { "size":0, "aggs":{ "avg_price":{ "avg":{ "field":"price" } } } }
4.2 terms桶 分组计数 { "size":0, "aggs":{ "by_tag":{ "terms":{ "field":"tags.keyword" } } } }
4.3 date_histogram 时间直方图 { "size":0, "aggs":{ "sales_per_day":{ "date_histogram":{ "field":"created","calendar_interval":"1d" } } } }
4.4 range桶 区间 { "size":0, "aggs":{ "price_ranges":{ "range":{ "field":"price","ranges":[ {"to":2000},{"from":2000,"to":5000},{"from":5000} ] } } } }
4.5 嵌套聚合 桶内再算指标 { "size":0, "aggs":{ "by_tag":{ "terms":{ "field":"tags.keyword" }, "aggs":{ "avg_price":{ "avg":{ "field":"price" } } } } } }

相关推荐
Sayai6 小时前
Elasticsearch 9 安装验证实战:start-local 一键部署 + Docker 手动安装踩坑指南
大数据·elasticsearch·docker
瑞码空间15 小时前
git知识点黄金笔记
笔记·git·elasticsearch
切糕师学AI18 小时前
如何查看已合并到 master 分支的所有分支?Git 分支清理指南
大数据·git·elasticsearch
suaizai_18 小时前
从1210条报错到全自动修复:AI闭环运维实战
大数据·elasticsearch·搜索引擎
Elastic 中国社区官方博客1 天前
不再有分配延迟:在无状态 Elasticsearch 中将快照与分片迁移解耦
大数据·运维·人工智能·elasticsearch·搜索引擎·全文检索
Elasticsearch1 天前
在 ES|QL 中引入 SPARKLINE:一眼看清趋势
elasticsearch
Capricorn19882 天前
防编造架构实战:对比 Gemini Notebook 解析知芽 Notebook Skill 的工程实现
人工智能·笔记·elasticsearch·架构·知识图谱·论文笔记
玉&心2 天前
在Kibana查看Elasticsearch中的日志或存储的文档数据
elasticsearch·kibana
Elastic 中国社区官方博客2 天前
安装 Elasticsearch
大数据·数据库·elasticsearch·搜索引擎·全文检索