您可以这样做:
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: onscript.file: on



