寻找指针以了解如何使用java api调用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与
test.groovy
config/scripts
config/elasticsearch.yml
script.inline: on script.file: on