Elasticsearch - 如何将脚本存储在 config/scripts 目录中

Elasticsearch - how to store scripts in config/scripts directory

我正在尝试使用 config/scripts 目录中的脚本。 Elasticsearch 文档 here 是这样说的:

Save the contents of the script as a file called config/scripts/my_script.groovy on every data node in the cluster:

这看起来可能真的很容易,但恐怕我不明白如何放置 groovy 文件 "on every data node in the cluster"。这通常是通过命令行以某种方式完成,还是可以通过手动移动 groovy 文件(例如在 OSX 上的 Finder 中)来完成?我有一个测试索引,但是当我查看节点上的文件结构时,我很困惑将 groovy 文件放在哪里。帮助,非常请。

你只需要将文件复制到每个服务器运行 elasticsearch。如果您的计算机上只有 运行 elasticsearch,则转到您安装了 elasticsearch 的文件夹,并将文件复制到其中的 config/scripts(您可能必须先创建该文件夹)。文件如何到达那里并不重要。

您应该会在日志中看到一个条目(如果您在前台 运行,则在控制台中看到)

compiling script file [/path/to/elasticsearch/config/scripts/my_script.groovy

这不会立即显示 - 默认情况下,elasticsearch 每 60 秒检查一次 new/updated 脚本(您可以使用 watcher.interval 设置更改此设置)

由于文件脚本已弃用 (elastic/elasticsearch#24552 & elastic/elasticsearch#24555),此方法将不再适用。

API这是唯一的办法。