☰
ES03-常用API
2026/10/14 1:59:19 网站建设 项目流程

ES03-常用API

文章目录

  • ES03-常用API
  • 1-参考网址
  • 2-知识总结
  • 3-高频核心操作速查表
    • 1-L1-Index
    • 2-L1-Doc
    • 3-L1-Query
    • 4-L1-Aggregations


1-参考网址

  • elasticsearch官网地址:https://www.elastic.co/
  • 安装elasticsearch9.0.0参考:https://zhuanlan.zhihu.com/p/1920780524991017021
  • 安装elasticsearch9.0.0参考:http://www.rhkb.cn/news/51907.html
  • 本地POSTMAN调试常用API:https://gitee.com/enzoism/postman-es

2-知识总结

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

3-高频核心操作速查表


1-L1-Index

#动作一句话请求示例
1.1创建索引指定 mapping/settings/aliasPUT /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 {"index":{"_index":"shop","_id":"2001"}}\n{"title":"iPhone"}\n

3-L1-Query

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

4-L1-Aggregations

#动作一句话请求示例
4.1avg/max/min指标{ "size":0, "aggs":{ "avg_price":{ "avg":{ "field":"price" } } } }
4.2terms桶分组计数{ "size":0, "aggs":{ "by_tag":{ "terms":{ "field":"tags.keyword" } } } }
4.3date_histogram时间直方图{ "size":0, "aggs":{ "sales_per_day":{ "date_histogram":{ "field":"created","calendar_interval":"1d" } } } }
4.4range桶区间{ "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" } } } } } }

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询