# elastic search 插件开发案例 **Repository Path**: water_and_moon_flowers/elastic-search-plugin ## Basic Information - **Project Name**: elastic search 插件开发案例 - **Description**: 这里存放一些es的插件开发代码,根据不同版本进行迭代,从简单到困难 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-01-05 - **Last Updated**: 2022-01-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README demo 地址:[https://gitee.com/water_and_moon_flowers/elastic-search-plugin/tree/master](https://gitee.com/water_and_moon_flowers/elastic-search-plugin/tree/master) 代码和包都有,内部代码也有注释,具体的代码含义可以看内部的代码注释 项目结构: ![image.png](https://cdn.nlark.com/yuque/0/2022/png/22306097/1641375139386-98461f48-03cb-4e4e-a307-28a7617457ac.png#clientId=uee8dd95b-e11c-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=411&id=u178101a3&margin=%5Bobject%20Object%5D&name=image.png&originHeight=411&originWidth=467&originalType=binary&ratio=1&rotation=0&showTitle=false&size=21149&status=done&style=none&taskId=u689e9bb8-e6d5-45d1-b0de-37706784fc6&title=&width=467) ​ 这里主要讲一下如何将代码打包成插件然后再如何安装进入es中: - 直接执行maven clean package, 具体的打包流程可以看我的pom文件,依赖于assembly,这里我写好了就不需要再改了,但注意一下下面的properties参数,随着elastic search版本不断的变动,plugin-descriptor.properties需要的参数也不同,可以查看elastic search的官网进行查看[https://www.elastic.co/guide/en/elasticsearch/plugins/current/plugin-authors.html](https://www.elastic.co/guide/en/elasticsearch/plugins/current/plugin-authors.html) ![image.png](https://cdn.nlark.com/yuque/0/2022/png/22306097/1641375039125-003091ad-a012-4d59-8e44-79a7b7c83605.png#clientId=uee8dd95b-e11c-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=367&id=uaf783c5d&margin=%5Bobject%20Object%5D&name=image.png&originHeight=367&originWidth=1038&originalType=binary&ratio=1&rotation=0&showTitle=false&size=32740&status=done&style=none&taskId=ue5b8b471-6155-406e-be2c-94553c4fa67&title=&width=1038) 这下面的就是plugin-descriptor.properties需要填充的参数 ![image.png](https://cdn.nlark.com/yuque/0/2022/png/22306097/1641375025816-62873c34-0baf-4a75-99ee-c1bb91b5aa57.png#clientId=uee8dd95b-e11c-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=184&id=uf157c183&margin=%5Bobject%20Object%5D&name=image.png&originHeight=184&originWidth=932&originalType=binary&ratio=1&rotation=0&showTitle=false&size=18366&status=done&style=none&taskId=u679ea5f7-b694-4724-b30a-99fd9b8af8d&title=&width=932) ​ - 一般而言,运行mvn clean package就可以在文件夹下获得一个target文件夹里面就有一个zip的文件(一定要有)。如果没有生成zip,可以查看一下maven的assembly是否运行,或者plugin.xml参数填写是否错误,我这个源码是自己运行通过了的,不会出现问题。 - 得到了zip以后,直接将这个zip放在elastic search的plugin目录下然后解压,删除这个zip(不删除不知道为什么会先加载zip文件导致错误) ![image.png](https://cdn.nlark.com/yuque/0/2022/png/22306097/1641375541756-1dfebdc5-55da-4094-afce-77fda2bb0d3a.png#clientId=uee8dd95b-e11c-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=94&id=u2dc7d52a&margin=%5Bobject%20Object%5D&name=image.png&originHeight=94&originWidth=400&originalType=binary&ratio=1&rotation=0&showTitle=false&size=5968&status=done&style=none&taskId=u923348bb-29f6-495e-9858-1a3de037e21&title=&width=400) - 我们这种方式是离线安装,之后直接导bin目录下启动es,如果运行没报错那么就没问题,当然你可以在代码中添加一些system.out.println() 来打印确定插件是否运行成功 ![image.png](https://cdn.nlark.com/yuque/0/2022/png/22306097/1641375645712-f594fd79-54b9-4952-86a3-4f9cc49619ed.png#clientId=uee8dd95b-e11c-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=256&id=u770ff146&margin=%5Bobject%20Object%5D&name=image.png&originHeight=256&originWidth=1332&originalType=binary&ratio=1&rotation=0&showTitle=false&size=46405&status=done&style=none&taskId=u8c5a48c9-28dd-4cd3-a33a-3e8fd826756&title=&width=1332) - 插件运行成功 ![image.png](https://cdn.nlark.com/yuque/0/2022/png/22306097/1641375691181-aa11a214-1f5b-4d68-ad87-5c730beb4d21.png#clientId=uee8dd95b-e11c-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=300&id=u70817847&margin=%5Bobject%20Object%5D&name=image.png&originHeight=300&originWidth=1918&originalType=binary&ratio=1&rotation=0&showTitle=false&size=34449&status=done&style=none&taskId=u2317eb00-bd81-404b-bde9-d02ed171c02&title=&width=1918) - 数据获取成功,这样就得到一个最简单的elastic search插件了。