类 若 实现NativeScriptFactory接口。A factory to create instances of either {@link ExecutableScript} or {@link SearchScript}

只是一个工厂类,仍需要 创建 上面二者之一。实际中 需 创建 类 继承 SearchScript接口的实现类AbstractSearchScript 的 子类@ AbstractLongSearchScript @AbstractDoubleSearchScript。

我们使用 它是因为public List<NativeScriptFactory> getNativeScripts() 需要返回的是工厂。

NativeScriptFactory

/**
* A factory to create instances of either {@link ExecutableScript} or {@link SearchScript}. Note,
* if this factory creates {@link SearchScript}, it must extend {@link AbstractSearchScript}.
*
* @see AbstractExecutableScript
* @see AbstractSearchScript
* @see AbstractLongSearchScript
* @see AbstractDoubleSearchScript
*/
public interface NativeScriptFactory {

ExecutableScript (一般不用,忽略)

* An executable script, can't be used concurrently.

SearchScript  接口

AbstractSearchScript (核心类,提供了绝大部分功能的实现)

/**
* A base class for any script type that is used during the search process (custom score, aggs, and so on).
* <p>
* If the script returns a specific numeric type, consider overriding the type specific base classes
* such as {@link AbstractDoubleSearchScript} and {@link AbstractLongSearchScript}
* for better performance.
* <p>
* The use is required to implement the {@link #run()} method.
*/
public abstract class AbstractSearchScript extends AbstractExecutableScript implements LeafSearchScript {

它 的核心是 属性:

private LeafSearchLookup lookup;
private Scorer scorer;

所有方法的实现同和这两个属性有关。

setLookup()实现lookup的初始化

通过SearchLookup调用lookup.getLeafSearchLookup(context)实现

searchLookUp则通过DefaultSearchContext.lookup()实现初始化

  lookup():  getQueryShardContext().lookup();

DefaultSearchContext则通过createContext实现初始化

也就是通过QueryShardContext.lookup() 实现。

QueryShardContext : lookup = new SearchLookup(getMapperService(), indexFieldDataService, types);

其主要属性 及初始化:

public class SearchLookup {

final DocLookup docMap;

final SourceLookup sourceLookup;

final FieldsLookup fieldsLookup;

public SearchLookup(MapperService mapperService, IndexFieldDataService fieldDataService, @Nullable String[] types) {
docMap = new DocLookup(mapperService, fieldDataService, types);
sourceLookup = new SourceLookup();
fieldsLookup = new FieldsLookup(mapperService, types);
}

public class FieldsLookup {

private final MapperService mapperService;
@Nullable
private final String[] types;

FieldsLookup(MapperService mapperService, @Nullable String[] types) {
this.mapperService = mapperService;
this.types = types;
}

然后追踪 传参的来源:

queryShardContext.setTypes(ShardSearchRequest.types());

LocalTransport.sendRequest()

  targetTransport.receiveMessage(version, data, action, requestId, this);

    processReceivedMessage(data, action, sourceTransport, version, requestId);

      StreamInput stream = StreamInput.wrap(data);

      handleRequest(stream, requestId, data.length, sourceTransport, version);

        request.readFrom(stream);

          TaskId.readFromStream(in);

            ShardSearchTransportRequest.readFrom()

              shardSearchLocalRequest.innerReadFrom(in);

                  types = in.readStringArray();

总结: 数据有了,直接用

plsSearchScript 继承自AbstractSearchScript 类。

覆写了run(),run方法会执行plsExScript接口的run().

我们只需要提供一个实现plsExScirpt接口的类

es 插件的更多相关文章

  1. 批量搞机(二):分布式ELK平台、Elasticsearch介绍、Elasticsearch集群安装、ES 插件的安装与使用

    一.分布式ELK平台 ELK的介绍: ELK 是什么? Sina.饿了么.携程.华为.美团.freewheel.畅捷通 .新浪微博.大讲台.魅族.IBM...... 这些公司都在使用 ELK!ELK! ...

  2. ELK搭建<二>:安装ES插件head

    1.去github下载head,针对ES版本不同,安装方式也不一样, =>在2.x以前版本可以通过插件安装 for Elasticsearch 2.x: sudo elasticsearch/b ...

  3. ES插件elasticsearch-mapper-attachments 2.3.4及各个版本正确下载地址

    ES版本更新那么快,文档链接你也倒是跟上啊, 插件zip包下载,都是error link...难不成是我网络原因? 下载zip页面报错信息: This XML file does not appear ...

  4. es插件安装

    首先安装找到一样版本的地址: Release v7.6.1 · medcl/elasticsearch-analysis-ik (github.com) 下载最上面的编译版 将文件解压到plugins ...

  5. ES插件升级

    #!/bin/bash mkdir -p /home/esuser cd /home/esuser wget http://10.12.xx.xx:8090/search_plugins/sd_wai ...

  6. #研发解决方案介绍#基于ES的搜索+筛选+排序解决方案

    郑昀 基于胡耀华和王超的设计文档 最后更新于2014/12/3 关键词:ElasticSearch.Lucene.solr.搜索.facet.高可用.可伸缩.mongodb.SearchHub.商品中 ...

  7. elasticsearch集群管理工具head插件(转)

    elasticsearch-head是一个elasticsearch的集群管理工具,它是完全由html5编写的独立网页程序,你可以通过插件把它集成到es 插件安装方法1: 1.elasticsearc ...

  8. ES的安装运行

    一.安装,运行 1. 检查java的版本环境 Elasticsearch依赖Java,在书写本文档的时候,推荐使用Oracle JDK 1.8.0_20 或 1.7.0_55以后的版本. 在安装Ela ...

  9. Elasticsarch及插件安装

    Elasticsarch及插件安装 一.环境介绍与安装准备 1.环境说明 OS为Centos 6.5,elasticsearch-1.1.X.tar.gz,         注:mongo river ...

随机推荐

  1. 【BZOJ4945】【NOI2017】游戏(搜索,2-sat)

    [NOI2017]游戏(搜索,2-sat) 题面 BZOJ的SPJ是假的 兹磁洛谷 题解 如果没有\(x\)地图的影响 这就是一个裸的\(2-sat\)问题 但是现在有不超过\(8\)个\(x\)地图 ...

  2. Unity3D手游开发日记(2) - 技能系统架构设计

    我想把技能做的比较牛逼,所以项目一开始我就在思考,是否需要一个灵活自由的技能系统架构设计,传统的技能设计,做法都是填excel表,技能需要什么,都填表里,很死板,比如有的技能只需要1个特效,有的要10 ...

  3. BZOJ3771 Triple 【NTT + 容斥】

    题目链接 BZOJ3771 题解 做水题放松一下 先构造\(A_i\)为\(x\)指数的生成函数\(A(x)\) 再构造\(2A_i\)为指数的生成函数\(B(x)\) 再构造\(3A_i\)为指数的 ...

  4. BZOJ 1070 修车 【费用流】

    Description 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同 的车进行维修所用的时间是不同的.现在需要安排这M位技术人员所维修的车及顺序, ...

  5. LUCAS定理简述

    Lucas定理解决的是n,m比较大而p是小于100000质数 简而言之就是Lucas(n,m)=C(n%p,m%p)*Lucas(n/p,m/p)%p; 其中组合数C是用任意一种计算10五次方内取模的 ...

  6. POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化)

    POJ.2528 Mayor's posters (线段树 区间更新 区间查询 离散化) 题意分析 贴海报,新的海报能覆盖在旧的海报上面,最后贴完了,求问能看见几张海报. 最多有10000张海报,海报 ...

  7. [ACM][2018南京预赛]Lpl and Energy-saving Lamps

    一.题面 样例输入: 5 4 3 10 5 2 7 10 5 1 4 8 7 2 3 6 4 7 样例输出: 4 0 1 1 3 6 5 1 5 1 2 0 3 2 4 4 3 6 5 1 二.思路 ...

  8. mybatis sql使用经验总结

    1.where 后面如果有动态sql,可以添加一个1=1条件,然后在后面添加动态sql语句,里面添加AND 例如: <select id="queryBizMonitorHistory ...

  9. 如何在Linux系统上安装QQ

    转载自KKK博客 首先我们需要在wine的官网上安装一个wine. https://wiki.winehq.org/Ubuntu_zhcn 按照上面的提示一步步来,做完之后点下面的链接下载 https ...

  10. 高并发大容量NoSQL解决方案探索

    大数据时代,企业对于DBA也提出更高的需求.同时,NoSQL作为近几年新崛起的一门技术,也受到越来越多的关注.本文将基于个推SRA孟显耀先生所负责的DBA工作,和大数据运维相关经验,分享两大方向内容: ...