专业查询编辑
这组包含查询不适应其他组:
- 这个查询发现文档类似于指定的文本,文档或文档的集合。
-
的
template
查询接受一个胡子模板(内联,索引,或者从一个文件),和一个映射的参数,结合了两个查询以生成最终的执行。 -
这个查询允许脚本作为一个过滤器。
也看到了
function_score
查询.
more_like_this
查询
template
查询
script
查询
QueryBuilder qb = moreLikeThisQuery("name.first", "name.last") //1
.like("text like this one") //2
.minTermFreq(1) //3
.maxQueryTerms(12); //4
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
您也可以将您的模板存储在一个名为特殊索引 .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
);
内联脚本 |