Elasticsearch5.6.16 api 集合
es:5.6.16
一、索引模板
1、创建索引模板
1 | PUT http://192.168.x.x:9201/_template/shop_template |
可参考:https://www.cnblogs.com/shoufeng/p/10641560.html
二、索引别名
1、
可参考:https://www.cnblogs.com/libin2015/p/10649189.html
三、索引操作
1、单一字段精准查询(查询字段是keyword):
1 | POST http://192.168.x.x:9201/access_log/_search |
2、时间范围查询:
1 | POST http://192.168.x.x:9201/access_log/_search |
参考资料:
https://www.cnblogs.com/shoufeng/p/11266136.html
https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-range-query.html
3、条件删除数据
https://www.elastic.co/guide/en/elasticsearch/reference/6.0/docs-delete-by-query.html
1 | curl -H 'Content-type: application/json' -XPOST 'http://es_ip:9201/events-hiostory/_delete_by_query' -d '{ |
1 | curl -H 'Content-type: application/json' -XPOST 'http://54.19.129.3:9200/events-history-system-2021111722/_delete_by_query' -d '{ |
4、查看索引 mapping 结构
1 | curl -XGET "http://x.x.x.x:9200/test-index/_mapping" |
5、查看索引列表,并根据索引大小倒序排序
1 | curl -XGET "http://172.26.x.x:9200/_cat/indices?format=json&index=*&s=store.size:desc,health,index,pri,rep,docs.count,mt" |
参考资料:https://www.elastic.co/guide/en/elasticsearch/reference/5.6/cat-indices.html#cat-indices
6、Filter 中 term 和 range 、search_after 同时使用(多条件查询)
1 | GET /_search |
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html
1 | 多条件组合 |
查询 xxx-index,获取要查询的 system 表
1 | { |
7、聚合某字段
1 | GET /test-index-*/test_type/_search |
8、根据Name分组,每组根据Time字段倒序排列,且只返回一条数据
1 | curl -H 'Content-type: application/json' -XGET 'http://192.168.x.x:9200/test-index-202201/_search' -d '{ |
参考资料:https://elasticsearch.cn/question/10928
9、多 term 查询
1 | { |
10、段合并相关操作
1 | 执行索引段合并 |
11、query、bool、filter
用 filter 包起来不会计算分值,可用来提高查询速度。
1 | { |
12、解决ES只能查询10000条数据的办法
1 | { |
java 代码:
1 | SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().trackTotalHits(true); |
注:适用于 7.6.x 版本
13、Bool 查询
Bool 查询现在包括四种子句,must、filter、should、must_not。
可参考:
14、ES from size分页
如果用 from size 的方式分页,默认只能查到 10 万条。10 万条之后,查询就会报错:
说到查询,ES 还有一个限制,查询返回的总条数,默认为 1 万。如果想要返回命中的实际总数量,可这样修改:
1 | { |
java 代码:
1 | SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().trackTotalHits(true); |
15、根据docId更新某文档
1 | curl -H 'Content-type: application/json' -XPOST 'http://x.x.x.x:9200/test-index-202212/doc/AYUI4HTL_6uoiy8Q9sy0/_update' -d '{ |
16、不等于
1 | { |
17、wildcard模糊查询
1 | { |
18、数据中含有 id 这个字段的数据
1 | { |
19、Match
分词匹配检索
1 | { |
20、match、fuzzy、wildcard 的区别
参考资料:https://blog.csdn.net/weixin_43859729/article/details/108134329
21、terms query
1 | { |
该语句等同于sql语句中的inList
22、匹配查询match
match和term的区别是,match查询的时候,elasticsearch会根据你给定的字段提供合适的分析器,而term查询不会有分析器分析的过程,match查询相当于模糊匹配,只包含其中一部分关键词就行
同时还要注意match系列匹配时,datatype要设置为text,否则不会开启分词。
点关注,不迷路
好了各位,以上就是这篇文章的全部内容了,能看到这里的人呀,都是人才。
白嫖不好,创作不易。各位的支持和认可,就是我创作的最大动力,我们下篇文章见!
如果本篇博客有任何错误,请批评指教,不胜感激 !
原文作者: create17
原文链接: https://841809077.github.io/2020/06/17/ELK/Elasticsearch/API/es-5-6-16-api-collection.html
版权声明: 转载请注明出处(码字不易,请保留作者署名及链接,谢谢配合!)