elasticsearch 打分插件

插件常用命令

./plugin list/remove/install

目录结构

plugin.xml 代码

<?xml version="1.0"?>
<assembly>
    <id>plugin</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <files>
        <file>
            <source>${project.basedir}/src/main/resources/plugin-descriptor.properties</source>
            <outputDirectory>elasticsearch</outputDirectory>
            <filtered>true</filtered>
        </file>
    </files>
    <dependencySets>
        <dependencySet>
            <outputDirectory>elasticsearch</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <useTransitiveFiltering>true</useTransitiveFiltering>
        </dependencySet>
    </dependencySets>
</assembly>

plugin-descriptor.properties 代码

description=my native script that does something great
version=1.0
name=my-native-scrip
classname=com.wuage.score.plugin.MyNativeScriptPlugin
java.version=1.8
elasticsearch.version=2.3.5
jvm=true

pom.xml 代码

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.wuage.es</groupId>
  <artifactId>score-plugins</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <name>score-plugins</name>
  
  
  <url>http://maven.apache.org</url>
  
  
 
    
  <dependencies>
             <dependency>
                <groupId>org.elasticsearch</groupId>
                <artifactId>elasticsearch</artifactId>
                <version>2.3.5</version>
                <scope>provided</scope>
            </dependency>
  </dependencies>
  
  
  <build>
        
        <plugins>
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.6</version>
          <configuration>
              <appendAssemblyId>false</appendAssemblyId>
              <outputDirectory>${project.build.directory}/releases/</outputDirectory>
              <descriptors>
                  <descriptor>${basedir}/src/main/assemblies/plugin.xml</descriptor>
              </descriptors>
          </configuration>
          <executions>
              <execution>
                  <phase>package</phase>
                  <goals>
                      <goal>single</goal>
                  </goals>
              </execution>
          </executions>
      </plugin>
      
      <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.5.1</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>
      
      
  </plugins>
        
       <resources>
         <resource>
            <directory>src/main/resources</directory>
            <filtering>false</filtering>
            <excludes>
                <exclude>*.properties</exclude>
            </excludes>
        </resource>
      </resources>
    </build>
 </project>

只有一个java 类 MyNativeScriptPlugin

public class MyNativeScriptPlugin extends Plugin {
    
    private static final ESLogger logger = Loggers.getLogger(MyNativeScriptPlugin.class);
    
    @Override
    public String name() {
        return "my-native-scrip";//native-script为插件的名称
    }
 
    @Override
    public String description() {
        return "new score rule";
    }
 
    public void onModule(ScriptModule module) {
        module.registerScript("my_script", MyNativeScriptFactory.class);
    }
    
    
    
    public static class MyNativeScriptFactory implements NativeScriptFactory {
        @Override
        public ExecutableScript newScript(@Nullable Map<String, Object> params) {
            return new MyNativeScript();
        }
        @Override
        public boolean needsScores() {
            return true;
        }
    }

    public static class MyNativeScript extends AbstractDoubleSearchScript {
        @Override
        public double runAsDouble() {
            try {
               //你的逻辑
                
            } catch (IOException e) {
                logger.error("",e);
            }
            
            return 0;
        }

    }
 
}

执行打包命令

mvn clean install

执行安装命令

/root/elasticsearch-2.3.5/bin/plugin install file:///root/score-plugins-1.0.0-SNAPSHOT.zip

需要所有机器都安装 否则报错 需要重启ES

执行查询命令

"script_score" : {
            "script" : { 
               "lang": "native",
               "inline":"my_script"  
             }
        }
时间: 2024-10-15 14:07:34

elasticsearch 打分插件的相关文章

ELK 学习笔记之 elasticsearch head插件安装

elasticsearch head插件安装: 准备工作: 安装nodejs和npm https://nodejs.org/en/download/ node-v6.11.2-linux-x64.tar.xz 由于是xz压缩文件,所以要先安装 yum -y install xz $xz -d ***.tar.xz $tar -xvf  ***.tar 配置环境变量 # set node environment export NODE_HOME=/usr/local/node-v6.11.2-li

Elasticsearch之插件扩展

Elasticsearch之插件介绍及安装 Elasticsearch之head插件安装之后的浏览详解 Elasticsearch之kopf插件安装之后的浏览详解 Elasticsearch-2.4.3的3节点安装(多种方式图文详解)(含 head.kopf和marvel插件安装) Elasticsearch之marvel(集群管理.监控)插件安装之后的浏览详解 Elasticsearch之shield(权限)插件安装之后的浏览详解 Elasticsearch之watcher(告警)插件安装之后

Elasticsearch.安装插件(head)

Elasticsearch.安装插件(head) 环境: Linux 7.x jdk1.8 目录结构(跟目录多了两个文件) /resources   ### 存放软件源 /u01/            ### 用来软件安装的目录     |- app 指令: # wget https://github.com/mobz/elasticsearch-head/archive/master.zip # unzip master.zip -d /u01/app #解压后在/u01/app里面多了一个

监控Elasticsearch的插件【check_es_system】

监控Elasticsearch的插件推荐  强大的shell脚本 #!/bin/bash ################################################################################ # Script: check_es_system.sh # # Author: Claudio Kuenzler www.claudiokuenzler.com # # Purpose: Monitor ElasticSearch Store (

Elasticsearch入门教程(一):Elasticsearch及插件安装

原文:Elasticsearch入门教程(一):Elasticsearch及插件安装 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/vbirdbest/article/details/79194244 分享一个朋友的人工智能教程(请以"右键"->"在新标签页中打开连接"的方式访问).比较通俗易懂,风趣幽默,感兴趣的朋友可以去看看. 一:安装Elasti

jquery数字打分插件与嵌入到EasyUI datagrid中的示例

这阵儿是断续折腾定性考评表打分的事儿了.虽是UI菜鸟,但却一直想让用户在操作上更加方便,之前基于"jQuery星级评分插件"实现了一个评分界面(因为比较简单,就不做总结了),用户反应还不错. 这一次的评分表中,各项分值的特点有:一是每个评分项的分值均不太一样:二是分值为整数,但分值范围大,从-1000到+1000都存在.若是采用在datagrid中嵌入编辑框的形式实现的话,总是觉得让用户使用不太方便,所以内心非常想做一个数字插件,然后就搜到中意的例子--"简单的jQuery用

elasticsearch 打分精度

elasticsearch 原文 What Is Relevance?edit We've mentioned that, by default, results are returned in descending order of relevance. But what is relevance? How is it calculated? The relevance score of each document is represented by a positive floating-p

Elasticsearch之插件介绍及安装

ES站点插件(以网页形式展现) 1.BigDesk Plugin (作者 Luká? Vl?ek) 简介:监控es状态的插件,推荐![目前不支持2.x] 2.Elasticsearch Head Plugin (作者 Ben Birch) (主要) 简介:很方便对es进行各种操作的客户端. 3.kopf Plugin(作者lmenezes) (主要) Kopf是一个ElasticSearch的管理工具,它也提供了对ES集群操作的API ES插件之Head Plugin 这个主要提供的是健康状态查

Elasticsearch报警插件Watch安装以及使用

参考:http://blog.csdn.net/ptmozhu/article/details/52296958 http://corejava2008.iteye.com/blog/2214279 一.watcher 插件安装1.在ES_HOME目录下安装License插件: bin/plugin install license2.安装watcher插件 bin/plugin install watcher3.重新启动Elasticsearch bin/elasticsearch4.验证是否安