如何使用 java api 为 Elasticsearch 调用 Groovy 脚本
How Groovy script can be invoked using java api for Elasticsearch
寻找指针以了解如何使用 java api.api.
调用 Groovy 脚本
test.groovy
def value = dynamicValue
return value
想要翻译 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
和
中启用了脚本
script.inline: on
script.file: on
寻找指针以了解如何使用 java api.api.
调用 Groovy 脚本test.groovy
def value = dynamicValue
return value
想要翻译 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
和
script.inline: on
script.file: on