2

I have the following document in elastic search:

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

And i am trying to update it using jestHttpClient with following code:

 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();
    }

}

But it is not updating the document , not sure what is wrong here,

Is there a way where we can partially update a document in elasticsearch?

Nkosi
  • 235,767
  • 35
  • 427
  • 472
Ankita Bhowmik
  • 463
  • 1
  • 5
  • 20
  • Did you make sure that you have [enabled dynamic scripting](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#enable-dynamic-scripting) in your `elasticsearch.yml` configuration file? – Val Mar 09 '16 at 07:00
  • i have downloaded elasticsearch using brew and i am new to MAC so can you help me find where i can locate elasticsearch.yml file. – Ankita Bhowmik Mar 09 '16 at 07:10
  • Using brew, ES has been installed in `/usr/local/Cellar/elasticsearch`, and the file you're looking for should be at `/usr/local/Cellar/elasticsearch/2.2.0/config/elasticsearch.yml` – Val Mar 09 '16 at 07:13
  • got it what should i add for updating ? – Ankita Bhowmik Mar 09 '16 at 07:28
  • According to the link I shared, you should add `script.inline: true`at the end of the file. – Val Mar 09 '16 at 07:29
  • Thanks @Val its working now :) Also you should add your comment as an answer. – Ankita Bhowmik Mar 09 '16 at 08:45

1 Answers1

1

You need to make sure that you have enabled dynamic scripting in your elasticsearch.yml configuration file.

Since you have installed ES using brew, you can normally find that configuration file at /usr/local/Cellar/elasticsearch/2.2.0/config/elasticsearch.yml

Simply append the following line to your file and restart ES:

script.inline: true

Your update script should work after that.

Val
  • 207,596
  • 13
  • 358
  • 360
  • i got a problem after enabling inline it is executing from rest but not from jest api not sure why? – Ankita Bhowmik Mar 09 '16 at 09:06
  • no it is not throwing any error just not updating the doc. – Ankita Bhowmik Mar 09 '16 at 09:07
  • Hmmm, does a [simple search](https://github.com/searchbox-io/Jest/tree/master/jest#searching-documents) or a [simple get](https://github.com/searchbox-io/Jest/tree/master/jest#getting-documents) via Jest work? – Val Mar 09 '16 at 09:33