{"id":16422978,"url":"https://github.com/vector4wang/elasticsearch-quick","last_synced_at":"2025-07-02T09:36:14.256Z","repository":{"id":31356763,"uuid":"127636068","full_name":"vector4wang/elasticsearch-quick","owner":"vector4wang","description":":mag::bar_chart:ElasticSearch的使用笔记,包括使用sdk，使用springboot+Jest、rollover索引切分和使用docker启动完成es的部署索引和搜索等","archived":false,"fork":false,"pushed_at":"2022-06-17T01:44:22.000Z","size":12354,"stargazers_count":84,"open_issues_count":4,"forks_count":23,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-01T23:23:01.191Z","etag":null,"topics":["charts","docker","elasticsearch","java","jest","springboot"],"latest_commit_sha":null,"homepage":"http://blog.wangxc.club","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vector4wang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-01T14:21:50.000Z","updated_at":"2024-12-17T17:39:58.000Z","dependencies_parsed_at":"2022-08-31T19:03:18.960Z","dependency_job_id":null,"html_url":"https://github.com/vector4wang/elasticsearch-quick","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vector4wang/elasticsearch-quick","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vector4wang%2Felasticsearch-quick","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vector4wang%2Felasticsearch-quick/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vector4wang%2Felasticsearch-quick/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vector4wang%2Felasticsearch-quick/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vector4wang","download_url":"https://codeload.github.com/vector4wang/elasticsearch-quick/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vector4wang%2Felasticsearch-quick/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263112473,"owners_count":23415623,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["charts","docker","elasticsearch","java","jest","springboot"],"created_at":"2024-10-11T07:38:33.035Z","updated_at":"2025-07-02T09:36:14.227Z","avatar_url":"https://github.com/vector4wang.png","language":"Java","readme":"\n[![LICENSE](https://img.shields.io/badge/license-Anti%20996-blue.svg)](https://github.com/996icu/996.ICU/blob/master/LICENSE)\n\n# quick-elasticsearch\nElasticSearch的使用笔记\n\n\n**如果你没有安装ELK，可以使用Docker安装，详见[Docker快速安装ELK](#Docker快速安装ELK)**\n\n\n这里除了会记录一些ES的使用代码和一些功能实现，也会有ELK的相关使用方法，如下图，比较简单的一个统计\n\n \n[![职位仪表盘.png](https://i.loli.net/2018/04/03/5ac333ab0021a.png)](https://i.loli.net/2018/04/03/5ac333ab0021a.png)\n\n代码里已经实现了\n\n- createIndex 创建索引\n- createMapping 创建mapping\n- putDocument 批量索引(包括数据已存在更新，不存在就插入)\n- deleteDocument\n\n目前再继续完善，如果感兴趣那就请持续关注~~~\n\n# ssb-jest-base\n\n[Branch](https://github.com/vector4wang/elasticsearch-quick/tree/sb-jest-base)\n\nSpringBoot使用jest替代官方sdk的使用方法\n\n简单易用，无需担心版本不兼容的问题\n\n配置好es的链接参数，直接运行项目，程序会自动的创建索引、mapping并且会插入几个文档供接下来的CURD使用\n\n如图\n[![es-view.png](https://i.loli.net/2018/08/04/5b65658ea06d5.png)](https://i.loli.net/2018/08/04/5b65658ea06d5.png)\n代码提供了最基本的增删改查功能\n[![swagger-api.png](https://i.loli.net/2018/08/04/5b65658ea31e2.png)](https://i.loli.net/2018/08/04/5b65658ea31e2.png)\n\n# ssb-jest\n\n[Branch](https://github.com/vector4wang/elasticsearch-quick/tree/sb-jest-analysis)\n\n此分支主要是处理分词和搜索相关问题\n使用IK分词 github地址：https://github.com/medcl/elasticsearch-analysis-ik\n按照上面的说明将插件放在~/elasticsearch/plugins/ik下面，重启即可\n\n\n## 分词情况\n\n可以这样对字符串进行分词分析\n```\npost http://localhost:9200/recipes/_analyze\n{\n  \"analyzer\": \"standard\", \n  \"text\": \"奶油鲍鱼汤\"\n}\n\n```\n### 默认分词器 Standard\n如果不指定分词，则会使用ES默认的分词，分词结果就会变成一个一个的字符，如下\n```json\n{\n    \"tokens\": [\n        {\n            \"token\": \"奶\",\n            \"start_offset\": 0,\n            \"end_offset\": 1,\n            \"type\": \"\u003cIDEOGRAPHIC\u003e\",\n            \"position\": 0\n        },\n        {\n            \"token\": \"油\",\n            \"start_offset\": 1,\n            \"end_offset\": 2,\n            \"type\": \"\u003cIDEOGRAPHIC\u003e\",\n            \"position\": 1\n        },\n        {\n            \"token\": \"鲍\",\n            \"start_offset\": 2,\n            \"end_offset\": 3,\n            \"type\": \"\u003cIDEOGRAPHIC\u003e\",\n            \"position\": 2\n        },\n        {\n            \"token\": \"鱼\",\n            \"start_offset\": 3,\n            \"end_offset\": 4,\n            \"type\": \"\u003cIDEOGRAPHIC\u003e\",\n            \"position\": 3\n        },\n        {\n            \"token\": \"汤\",\n            \"start_offset\": 4,\n            \"end_offset\": 5,\n            \"type\": \"\u003cIDEOGRAPHIC\u003e\",\n            \"position\": 4\n        }\n    ]\n}\n```\n\n### IK分词\n在创建mapping的时候指定分词，如下\n```json\n\"jobName\": {\n  \"type\": \"text\",\n  \"analyzer\": \"ik_max_word\",\n  \"search_analyzer\": \"ik_max_word\"\n}\n```\nik分词有两种模式\n- ik_max_word\n```\n{\n    \"tokens\": [\n        {\n            \"token\": \"奶油\",\n            \"start_offset\": 0,\n            \"end_offset\": 2,\n            \"type\": \"CN_WORD\",\n            \"position\": 0\n        },\n        {\n            \"token\": \"鲍鱼\",\n            \"start_offset\": 2,\n            \"end_offset\": 4,\n            \"type\": \"CN_WORD\",\n            \"position\": 1\n        },\n        {\n            \"token\": \"鱼汤\",\n            \"start_offset\": 3,\n            \"end_offset\": 5,\n            \"type\": \"CN_WORD\",\n            \"position\": 2\n        }\n    ]\n}\n```\n- ik_smart\n```\n{\n    \"tokens\": [\n        {\n            \"token\": \"奶油\",\n            \"start_offset\": 0,\n            \"end_offset\": 2,\n            \"type\": \"CN_WORD\",\n            \"position\": 0\n        },\n        {\n            \"token\": \"鲍\",\n            \"start_offset\": 2,\n            \"end_offset\": 3,\n            \"type\": \"CN_CHAR\",\n            \"position\": 1\n        },\n        {\n            \"token\": \"鱼汤\",\n            \"start_offset\": 3,\n            \"end_offset\": 5,\n            \"type\": \"CN_WORD\",\n            \"position\": 2\n        }\n    ]\n}\n```\n能直观的看出两者的区别，当然了IK也支持自定义呢分词字典，这个去github主页就能看到使用方法。\n\n## 查询\n\n[点我](http://www.cnblogs.com/yjf512/p/4897294.html)看term和match的区别\n\n\n# ES 7.x 下的Jest测试\n\n[Branch](https://github.com/vector4wang/elasticsearch-quick)\n\n注意： *取消了type*\n\n目前jest对es的版本支持对应关系如下\n\nJest Version | Elasticsearch Version\n--- | ---\n\\\u003e= 6.0.0 | 6\n\\\u003e= 5.0.0 | 5\n\\\u003e= 2.0.0 | 2\n0.1.0 - 1.0.0 | 1\n\u003c= 0.0.6 | \u003c 1\n\n所以目前还没有针对es 7.x的版本，但是jest聪明的是，它的请求与返回都是可以拼接的，我们可以把请求参数中的type置空，然后在响应体中，可以直接获取jsonstring\n当然了es7.0 改版的只是一小部分接口，大多数的都不需要怎么改变，但是一定要测试过了才能切换~\n\n个人使用和测试api的方式，分别打开如下两个链接\n\nhttps://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html\n\nhttps://github.com/searchbox-io/Jest/blob/master/jest/src/test/java/io/searchbox/indices/GetMappingIntegrationTest.java\n\n一个是ES的官方文档，一个是jest的IntegrationTest，两者结合，效率杠杠的~~~~\n\n# ES 聚合示例\n\n\n[Branch](https://github.com/vector4wang/elasticsearch-quick/tree/sb-jest-aggregation)\n聚合脚本的示例，包括普通聚合，netsted聚合查询统计等等，后面用到哪些再继续补充\n\n## Docker快速安装ELK\n\n首先在[Dockerhub](https://hub.docker.com/r/sebp/elk)找到对应的版本号(不同版本号的用法有点区别，需要注意！)\n\n\n```bash\n# 7.0\ndocker pull sebp/elk:700\n# 2.3.5\ndocker pull sebp/elk:es235_l234_k454\n\n```\n页面上有版本号的对应关系，找准即可\n\n然后进入[帮助页面](https://elk-docker.readthedocs.io/) 因为只需要使用ES的9200端口和Kibana的5601端口，所以这样启动\n```bash\ndocker run -p 5601:5601 -p 9200:9200 -p 5044:5044 -it --name elk sebp/elk\n```\n端口关系如下图：\n![port](http://cdn.wangxc.club/Og5eps4.png)\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvector4wang%2Felasticsearch-quick","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvector4wang%2Felasticsearch-quick","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvector4wang%2Felasticsearch-quick/lists"}