elasticsearch5.2.2 插件开发(一)

本文地址http://blog.youkuaiyun.com/makefriend7/article/details/60323717


首先放上官网地址https://www.elastic.co/guide/en/elasticsearch/plugins/5.2/index.html


一,插件介绍

插件,大家听名字就知道,就是在ES上插入一个东西,来增强ES的能力。

这里先简单介绍一下插件的分类

  • API extension plugin(ActionPlugin): 就是扩展ES的API函数的。大部分是用来search和mapping, 比如 让ES支持SQL 语句
  • Alerting plugins: 监控索引,当超越阈值的时候,则自动触发报警(代表插件X-PACK,在你设置了某种查询条件之后,他会周期性的去调用,如果满足条件,则做指定要求做的事)
  • Analysis plugins:分析插件,简单说,就是制定建立索引规则的插件,比如SmartCN,就是一个中文分词插件,根据中文来建立索引(而不是英文的空格),以句,词发方式建立索引
  • Discovery plugins:发现插件,简单的说。就是集群如何发现属于自己的服务器。按照官方的说法,就是在一个cluster中,如何选举出一个主要的node.
  • The ingest plugins: 这个插件的主要功能就是增强每个节点的功能。比如Ingest Attcahment Processor Plugin 就可以让每个节点解压文件,处理诸如PPT ,XLD ,PDF的文件格式
  • Management plugins: 管理插件,当然是对ES进行交互和管理(比如X-PACK)
  • Mapper plugins: 这个插件主要就是增强ES的数据类型。比如增加一个attachment类型,里面可以放PDF或者WORD数据
  • Scripting plugins:这个插件本质来说,就是会调用用户的脚本,所以可以执行任何的程序,举例的话,可以通过这个插件,支持javascript语言,python语言,也可以是用户自定义的任何语言或者程序。
  • Security plugins:当然就是提供安全的控制,比如控制哪些用户可以使用ES的那些API
  • Repository plugins:提供快照和恢复,简单的理解,就是你把数据放在了服务器上,别人可以通过共享文件夹访问你的数据,也可以通过共享文件夹恢复你的数据。目前ES的核心插件已经支持S3,HDFS等很多访问方式。
  • Store plugins, 我们知道ES实际使用的是Lucene 来进行存储的。我们也可以采用Store SMB.(windows的共享文件协议)
二,额外的工具,这是用来帮助其他系统来使用ES的。

1. 内容管理系统

  • Drupal:Drupal是使用PHP语言编写的开源内容管理框架(CMF)
  • Wp-Elasticsearch: ES的 WordPress 插件 即WordPress可以直接使用ES
  • 还有Elasticsearch, Tiki Wiki Cms Groupware  XWIKI Next Generation Wiki
2. 数据导入导出和校验
  • LogStash output to ES 和ES input to LogStash
  • ES event filtering in Logstash
  • ES bulk codec
  • JDBC importer : 将jdbc的源数据导入到ES
  • Kafka Standalone consumer(Indexer) :将kafka数据导入ES
  • Mongolastic : 将ES数据导入MongoDB
  • Scrutineer: 索引和内容的校验工具
  • IMAP/POP3/MAIL importer : 将IMAP POP3 的数据导入到ES(邮箱数据也能进ES啦)
  • FS Crawler: 索引文件系统(如PDF ,OPEN OFFICE 。。。) 本地的,或者通过SSH
3. 部署
ES 提供Puppet   社区提供Chef

3. 框架整合

4.Hadoop integrations

4.其他整合
pes : 支持JS 的  DSL查询 https://github.com/kodcu/pes

二,第一个PLUGIN程序
插件程序是非常简单的。代码如下

[java]  view plain  copy
  1. public class MyFirstPlugin extends Plugin{  
  2.     private final static Logger LOGGER = LogManager.getLogger(MyFirstPlugin.class);  
  3.     public MyFirstPlugin() {  
  4.         super();  
  5.         LOGGER.warn("This is my fisrt Plugin");  
  6.     }  
  7. }  


补上pomx.ml

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.          xmlns="http://maven.apache.org/POM/4.0.0"  
  4.          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  5.     <modelVersion>4.0.0</modelVersion>  
  6.   
  7.     <groupId>mygroup1</groupId>  
  8.     <artifactId>myart1</artifactId>  
  9.     <version>5.2.2-SNAPSHOT</version>  
  10.     <name>Plugin: Basic</name>  
  11.     <description>Only for test</description>  
  12.   
  13.   
  14.     <properties>  
  15.         <elasticsearch.version>5.2.2</elasticsearch.version>  
  16.         <lucene.version>6.4.1</lucene.version>  
  17.     </properties>  
  18.     <dependencies>  
  19.         <dependency>  
  20.             <groupId>org.elasticsearch</groupId>  
  21.             <artifactId>elasticsearch</artifactId>  
  22.             <version>${elasticsearch.version}</version>  
  23.             <scope>provided</scope>  
  24.         </dependency>  
  25.   
  26.         <!-- Testing -->  
  27.         <dependency>  
  28.             <groupId>org.apache.logging.log4j</groupId>  
  29.             <artifactId>log4j-api</artifactId>  
  30.             <version>2.7</version>  
  31.             <scope>provided</scope>  
  32.         </dependency>  
  33.         <dependency>  
  34.             <groupId>org.apache.logging.log4j</groupId>  
  35.             <artifactId>log4j-core</artifactId>  
  36.             <version>2.7</version>  
  37.             <scope>test</scope>  
  38.         </dependency>  
  39.         <dependency>  
  40.             <groupId>org.elasticsearch.test</groupId>  
  41.             <artifactId>framework</artifactId>  
  42.             <version>${elasticsearch.version}</version>  
  43.             <scope>test</scope>  
  44.         </dependency>  
  45.   
  46.         <dependency>  
  47.             <groupId>org.apache.lucene</groupId>  
  48.             <artifactId>lucene-test-framework</artifactId>  
  49.             <version>${lucene.version}</version>  
  50.             <scope>test</scope>  
  51.         </dependency>  
  52.     </dependencies>  
  53.   
  54.     <build>  
  55.         <resources>  
  56.             <resource>  
  57.                 <directory>src/main/resources</directory>  
  58.                 <filtering>false</filtering>  
  59.                 <excludes>  
  60.                     <exclude>*.properties</exclude>  
  61.                 </excludes>  
  62.             </resource>  
  63.         </resources>  
  64.         <plugins>  
  65.             <plugin>  
  66.                 <groupId>org.apache.maven.plugins</groupId>  
  67.                 <artifactId>maven-assembly-plugin</artifactId>  
  68.                 <version>2.6</version>  
  69.                 <configuration>  
  70.                     <appendAssemblyId>false</appendAssemblyId>  
  71.                     <outputDirectory>${project.build.directory}/releases/</outputDirectory>  
  72.                     <descriptors>  
  73.                         <descriptor>${basedir}/src/main/assemblies/plugin.xml</descriptor>  
  74.                     </descriptors>  
  75.                 </configuration>  
  76.                 <executions>  
  77.                     <execution>  
  78.                         <phase>package</phase>  
  79.                         <goals>  
  80.                             <goal>single</goal>  
  81.                         </goals>  
  82.                     </execution>  
  83.                 </executions>  
  84.             </plugin>  
  85.             <plugin>  
  86.                 <groupId>org.apache.maven.plugins</groupId>  
  87.                 <artifactId>maven-compiler-plugin</artifactId>  
  88.                 <version>3.3</version>  
  89.                 <configuration>  
  90.                     <source>1.8</source>  
  91.                     <target>1.8</target>  
  92.                 </configuration>  
  93.             </plugin>  
  94.         </plugins>  
  95.     </build>  
  96. </project>  


运行命令 mvn clean install
在release目录下得到myart1-5.2.2-SNAPSHOT.zip文件
在ES目录运行
bin\elasticsearch-plugin install file:///D:/greesoft/elastic/myart1-5.2.2-SNAPSHOT.zip
就安装插件完成了,

此处有个小坑。在windows下。java安装的目录一般会有空格。此处简单的 修改 elasticsearch-plugin.bat文件 如下

set JAVA=D:\jdk1.8.0_102\bin\java.exe  (我放的JAVA位置,省得处理空格了)


运行ES。就可以看到我们的打出的信息了。


补上pom.xml

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.          xmlns="http://maven.apache.org/POM/4.0.0"  
  4.          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  5.     <modelVersion>4.0.0</modelVersion>  
  6.   
  7.     <groupId>mygroup1</groupId>  
  8.     <artifactId>myart1</artifactId>  
  9.     <version>5.2.2-SNAPSHOT</version>  
  10.     <name>Plugin: Basic</name>  
  11.     <description>Only for test</description>  
  12.   
  13.   
  14.     <properties>  
  15.         <elasticsearch.version>5.2.2</elasticsearch.version>  
  16.         <lucene.version>6.4.1</lucene.version>  
  17.     </properties>  
  18.     <dependencies>  
  19.         <dependency>  
  20.             <groupId>org.elasticsearch</groupId>  
  21.             <artifactId>elasticsearch</artifactId>  
  22.             <version>${elasticsearch.version}</version>  
  23.             <scope>provided</scope>  
  24.         </dependency>  
  25.   
  26.         <!-- Testing -->  
  27.         <dependency>  
  28.             <groupId>org.apache.logging.log4j</groupId>  
  29.             <artifactId>log4j-api</artifactId>  
  30.             <version>2.7</version>  
  31.             <scope>provided</scope>  
  32.         </dependency>  
  33.         <dependency>  
  34.             <groupId>org.apache.logging.log4j</groupId>  
  35.             <artifactId>log4j-core</artifactId>  
  36.             <version>2.7</version>  
  37.             <scope>test</scope>  
  38.         </dependency>  
  39.         <dependency>  
  40.             <groupId>org.elasticsearch.test</groupId>  
  41.             <artifactId>framework</artifactId>  
  42.             <version>${elasticsearch.version}</version>  
  43.             <scope>test</scope>  
  44.         </dependency>  
  45.   
  46.         <dependency>  
  47.             <groupId>org.apache.lucene</groupId>  
  48.             <artifactId>lucene-test-framework</artifactId>  
  49.             <version>${lucene.version}</version>  
  50.             <scope>test</scope>  
  51.         </dependency>  
  52.     </dependencies>  
  53.   
  54.     <build>  
  55.         <resources>  
  56.             <resource>  
  57.                 <directory>src/main/resources</directory>  
  58.                 <filtering>false</filtering>  
  59.                 <excludes>  
  60.                     <exclude>*.properties</exclude>  
  61.                 </excludes>  
  62.             </resource>  
  63.         </resources>  
  64.         <plugins>  
  65.             <plugin>  
  66.                 <groupId>org.apache.maven.plugins</groupId>  
  67.                 <artifactId>maven-assembly-plugin</artifactId>  
  68.                 <version>2.6</version>  
  69.                 <configuration>  
  70.                     <appendAssemblyId>false</appendAssemblyId>  
  71.                     <outputDirectory>${project.build.directory}/releases/</outputDirectory>  
  72.                     <descriptors>  
  73.                         <descriptor>${basedir}/src/main/assemblies/plugin.xml</descriptor>  
  74.                     </descriptors>  
  75.                 </configuration>  
  76.                 <executions>  
  77.                     <execution>  
  78.                         <phase>package</phase>  
  79.                         <goals>  
  80.                             <goal>single</goal>  
  81.                         </goals>  
  82.                     </execution>  
  83.                 </executions>  
  84.             </plugin>  
  85.             <plugin>  
  86.                 <groupId>org.apache.maven.plugins</groupId>  
  87.                 <artifactId>maven-compiler-plugin</artifactId>  
  88.                 <version>3.3</version>  
  89.                 <configuration>  
  90.                     <source>1.8</source>  
  91.                     <target>1.8</target>  
  92.                 </configuration>  
  93.             </plugin>  
  94.         </plugins>  
  95.     </build>  
  96. </project>  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值