如何使用Java api为Elasticsearch调用Groovy脚本 [英] How Groovy script can be invoked using java api for Elasticsearch
本文介绍了如何使用Java api为Elasticsearch调用Groovy脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
寻找指针,了解如何使用java api调用Groovy脚本。
Looking for pointers to know how Groovy script can be invoked using java api.
test.groovy
def value = dynamicValue
return value
想要在Java中翻译以下查询:
Want to translate following query in Java:
GET /test-index/_search
{
"query": {
"match_all": {}
},
"script_fields": {
"checkValue": {
"script": "test",
"params": {
"dynamicValue": 7
}
}
}
}
推荐答案
你可以这样做:
Map<String, Object> params = ImmutableMap.of("dynamicValue", 7);
SearchResponse response = client().prepareSearch("test-index")
.setQuery(matchAllQuery())
.addScriptField("checkValue", new Script("test", ScriptType.FILE, "groovy", params))
.execute().actionGet();
您需要存储您的 test.groovy
文件在每个数据节点上的 config / scripts
文件夹中,并确保脚本在 config / elasticsearch.yml
中启用
$ b
You need to store your test.groovy
file in the config/scripts
folder on each data node and also make sure scripting is enabled in config/elasticsearch.yml
with
script.inline: on
script.file: on
这篇关于如何使用Java api为Elasticsearch调用Groovy脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文