使用 updateBuilder 时 Elasticsearch 部分更新没有发生

Elasticsearch partial update not happening while using updateBuilder

我在弹性搜索中有以下文档:

   {
      "postDate": "2016-03-09T11:57:37+0530",
      "message": "trying out Elasticsearch",
      "user": "ankita",
      "tags": [
        "testing"
      ]
    }

我正在尝试使用 jestHttpClient 和以下代码更新它:

 private static void updateDocument(JestClient client, String id) {


    String script = "{\n" +
            "    \"script\" : \"ctx._source.tags += tag\",\n" +
            "    \"params\" : {\n" +
            "        \"tag\" : \"blue\"\n" +
            "    }\n" +
            "}";
    //String script ="{ \"script\" : \"ctx._source.newfield = \"something\"\"}";
    try {
        Update update=new Update.Builder(script).index("article").type("type").id(id).build();
        client.execute(update);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

但是没有更新文档,不知道哪里出了问题,

有没有办法在 elasticsearch 中部分更新文档?

您需要确保 enabled dynamic scripting 在您的 elasticsearch.yml 配置文件中。

因为你是用brew安装ES的,所以一般可以在/usr/local/Cellar/elasticsearch/2.2.0/config/elasticsearch.yml

找到那个配置文件

只需将以下行附加到您的文件并重新启动 ES:

script.inline: true

之后您的更新脚本应该可以运行。