Elasticsearch java API (24)查询 DSL Specialized(专业)查询

专业查询编辑

这组包含查询不适应其他组:

more_like_this 查询
这个查询发现文档类似于指定的文本,文档或文档的集合。
template 查询
 template 查询接受一个胡子模板(内联,索引,或者从一个文件),和一个映射的参数,结合了两个查询以生成最终的执行。
script 查询
这个查询允许脚本作为一个过滤器。 也看到了  function_score查询.

更像这个查询(mlt)编辑

看到:*更像这个查询

QueryBuilder qb = moreLikeThisQuery("name.first", "name.last") //1
    .like("text like this one")                                //2
    .minTermFreq(1)                                            //3
    .maxQueryTerms(12);                                        //4

字段

文本

忽略阈值

马克斯num的术语在生成查询

查询模板编辑

看到搜索模板文档

定义你的模板参数 Map<String,Object>:

Map<String, Object> template_params = new HashMap<>();
template_params.put("param_gender", "male");
你可以用你的存储搜索模板  config/scripts 例如,如果你有一个文件命名 config/scripts/template_gender.mustache 包含:
{
    "template" : {
        "query" : {
            "match" : {
                "gender" : "{{param_gender}}"
            }
        }
    }
}
定义模板查询:
QueryBuilder qb = templateQuery(
    "gender_template",               //1   
    ScriptService.ScriptType.FILE,      //2
    template_params);                   //3

模板名称

模板存储在磁盘上 gender_template.mustache

参数

您也可以将您的模板存储在一个名为特殊索引 .scripts:

client.preparePutIndexedScript("mustache", "template_gender",
        "{\n" +
        "    \"template\" : {\n" +
        "        \"query\" : {\n" +
        "            \"match\" : {\n" +
        "                \"gender\" : \"{{param_gender}}\"\n" +
        "            }\n" +
        "        }\n" +
        "    }\n" +
        "}").get();
执行索引模板,使用  ScriptService.ScriptType.INDEXED :
QueryBuilder qb = templateQuery(
    "gender_template",                  //1
    ScriptService.ScriptType.INDEXED,   //2
    template_params);                   //3

模板名称

模板保存在索引中

参数

脚本查询编辑

看到脚本查询

QueryBuilder qb = scriptQuery(
    new Script("doc['num1'].value > 1") //1
);


内联脚本





  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值