# Using Scripts for Documents Updating

**URL:** <https://discuss.elastic.co/t/using-scripts-for-documents-updating/85968>\
**Category:** Elasticsearch\
**Created:** [May 16, 2017, 3:24pm UTC](https://discuss.elastic.co/t/using-scripts-for-documents-updating/85968 "2017-05-16T15:24:12Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giuseppe\_Merlo](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@Giuseppe\_Merlo](https://discuss.elastic.co/u/Giuseppe_Merlo)\
**Post date:** [May 16, 2017, 3:24pm UTC](https://discuss.elastic.co/t/using-scripts-for-documents-updating/85968/1 "2017-05-16T15:24:13Z")

</div>

Hi,

i'm just trying to use script because i want to update by 1 my field data. I want to make a request like this:

```ruby
curl -XPOST 'http://localhost:9200/asl/tot/2/_update' -d '{"script" : "ctx._source.conta += 1"}'

```

and the ElasticSearch answer is:

```ruby
scripts of type [inline], operation [update] and lang [groovy] are disabled

```

I try to add in elasticsearch.yml both **script.engine.groovy.inline.search: on** , **script.groovy.sandbox.enabled: true** and  
**script.inline: on**  
**script.indexed: on**

but Elasticsearch doesn't start and returns this error:

```ruby
expected '<document start>', but found Block Mapping Start elasticsearch

```

Can someone help me?

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![ahmadimt07](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmadimt07/32/10031_2.png) [@ahmadimt07](https://discuss.elastic.co/u/ahmadimt07)\
**Post date:** [May 17, 2017, 10:01am UTC](https://discuss.elastic.co/t/using-scripts-for-documents-updating/85968/2 "2017-05-17T10:01:00Z")

</div>

It seems that there is an error in your elasticsearch.yml. Can you please post your elasticsearch.yml. This will help in determining the error

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Merlo](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@Giuseppe\_Merlo](https://discuss.elastic.co/u/Giuseppe_Merlo)\
**Post date:** [May 17, 2017, 10:39am UTC](https://discuss.elastic.co/t/using-scripts-for-documents-updating/85968/3 "2017-05-17T10:39:06Z")

</div>

This is my elasticsearch.yml file:

```ruby
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please see the documentation for further information on configuration options:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html>
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
# cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
# node.name: node-1
#
# Add custom attributes to the node:
#
# node.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
# path.data: /path/to/data
#
# Path to log files:
#
# path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
# bootstrap.memory_lock: true
#
# Make sure that the `ES_HEAP_SIZE` environment variable is set to about half the memory
# available on the system and that the owner of the process is allowed to use this limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
 network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
# http.port: 9200
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
# discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):
#
# discovery.zen.minimum_master_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
# gateway.recover_after_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html>
#
# ---------------------------------- Various -----------------------------------
#
# Disable starting multiple nodes on a single system:
#
# node.max_local_storage_nodes: 1
#
# Require explicit names when deleting indices:
#
# action.destructive_requires_name: true

```

---

<div class="post-metadata">

**Author:** ![ahmadimt07](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmadimt07/32/10031_2.png) [@ahmadimt07](https://discuss.elastic.co/u/ahmadimt07)\
**Post date:** [May 17, 2017, 3:55pm UTC](https://discuss.elastic.co/t/using-scripts-for-documents-updating/85968/4 "2017-05-17T15:55:43Z")

</div>

What version of Elasticsearch are you using??  
May be this can help you more

[https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-groovy.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-groovy.html)

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Merlo](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@Giuseppe\_Merlo](https://discuss.elastic.co/u/Giuseppe_Merlo)\
**Post date:** [May 18, 2017, 6:39am UTC](https://discuss.elastic.co/t/using-scripts-for-documents-updating/85968/5 "2017-05-18T06:39:00Z")

</div>

```ruby
{
  "name" : "Mac Gargan",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "mQ2s3nx7RHG--Gcvkd-G7A",
  "version" : {
    "number" : "2.4.4",
    "build_hash" : "fcbb46dfd45562a9cf00c604b30849a6dec6b017",
    "build_timestamp" : "2017-01-03T11:33:16Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.2"
  },
  "tagline" : "You Know, for Search"
}

```

I have already read that link documentation..

---

<div class="post-metadata">

**Author:** ![ahmadimt07](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmadimt07/32/10031_2.png) [@ahmadimt07](https://discuss.elastic.co/u/ahmadimt07)\
**Post date:** [May 20, 2017, 2:51am UTC](https://discuss.elastic.co/t/using-scripts-for-documents-updating/85968/6 "2017-05-20T02:51:43Z")

</div>

Hi Giuseppe,

I have done following setting in my `elasticsearch.yml` file and it is working fine for me:  
`script.inline: true script.indexed: true`

My config file is as follows:

```
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please see the documentation for further information on configuration options:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html>
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
# cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
# node.name: node-1
#
# Add custom attributes to the node:
#
# node.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
# path.data: /path/to/data
#
# Path to log files:
#
# path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
# bootstrap.memory_lock: true
#
# Make sure that the `ES_HEAP_SIZE` environment variable is set to about half the memory
# available on the system and that the owner of the process is allowed to use this limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
# network.host: 192.168.0.1
#
# Set a custom port for HTTP:
#
# http.port: 9200
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
# discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):
#
# discovery.zen.minimum_master_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
# gateway.recover_after_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html>
#
# ---------------------------------- Various -----------------------------------
#
# Disable starting multiple nodes on a single system:
#
# node.max_local_storage_nodes: 1
#
# Require explicit names when deleting indices:
#
# action.destructive_requires_name: true

script.inline: true
script.indexed: true

```

NOTE: After adding these properties, you will have to restart Elasticsearch.

Here is the script I ran and it's result:

`ubuntu@imteyaz:~/Downloads/elasticsearch-2.4.4$ curl -XPOST '[http://localhost:9200/asl/tot/1/\_update](http://localhost:9200/asl/tot/1/_update)' -d '{"script" : "ctx.\_source.conta += 1"}'

{"\_index":"asl","\_type":"tot","\_id":"1","\_version":2,"\_shards":{"total":2,"successful":1,"failed":0}}`

Before running the script, the count was 1:  
 ![](https://us1.discourse-cdn.com/elastic/original/3X/e/1/e123c6c899b9eb5c8e718160cfccbe2babcf392c.png)

After executing the script, the count is 2:  
 ![](https://us1.discourse-cdn.com/elastic/original/3X/0/f/0f819f942c3a4b25b33e42abe30da4d72d19297d.png)

Hope it is helpful.

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Merlo](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@Giuseppe\_Merlo](https://discuss.elastic.co/u/Giuseppe_Merlo)\
**Post date:** [May 22, 2017, 9:14am UTC](https://discuss.elastic.co/t/using-scripts-for-documents-updating/85968/7 "2017-05-22T09:14:29Z")

</div>

Thanks for your reply!! I'll try to do it ASAP and get you my results!

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Merlo](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@Giuseppe\_Merlo](https://discuss.elastic.co/u/Giuseppe_Merlo)\
**Post date:** [May 22, 2017, 1:32pm UTC](https://discuss.elastic.co/t/using-scripts-for-documents-updating/85968/8 "2017-05-22T13:32:58Z")

</div>

Hi ahmadimt,

i tried to add script.inline : true and script.indexed: true as you suggested, but i've got the same error:

```
expected '<document start>', but found Block Mapping Start elasticsearch

```

For having idea of it, this is my Elasticsearch.yml file:

```
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please see the documentation for further information on configuration options:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html>
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
# cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
# node.name: node-1
#
# Add custom attributes to the node:
#
# node.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
# path.data: /path/to/data
#
# Path to log files:
#
# path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
# bootstrap.memory_lock: true
#
# Make sure that the `ES_HEAP_SIZE` environment variable is set to about half the memory
# available on the system and that the owner of the process is allowed to use this limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
 network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
# http.port: 9200
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
# discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):
#
# discovery.zen.minimum_master_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
# gateway.recover_after_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html>
#
# ---------------------------------- Various -----------------------------------
#
# Disable starting multiple nodes on a single system:
#
# node.max_local_storage_nodes: 1
#
# Require explicit names when deleting indices:
#
# action.destructive_requires_name: true

script.inline: true
script.indexed: true

```

Thanks for all your support

---

<div class="post-metadata">

**Author:** ![ahmadimt07](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmadimt07/32/10031_2.png) [@ahmadimt07](https://discuss.elastic.co/u/ahmadimt07)\
**Post date:** [May 22, 2017, 2:23pm UTC](https://discuss.elastic.co/t/using-scripts-for-documents-updating/85968/9 "2017-05-22T14:23:52Z")

</div>

Please remove space from this key....."network.host: 0.0.0.0". The issue is the blank space before this.

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Merlo](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@Giuseppe\_Merlo](https://discuss.elastic.co/u/Giuseppe_Merlo)\
**Post date:** [May 23, 2017, 6:45am UTC](https://discuss.elastic.co/t/using-scripts-for-documents-updating/85968/10 "2017-05-23T06:45:26Z")

</div>

Yeah, that works! Thank you for all your support. 😀

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 20, 2017, 6:45am UTC](https://discuss.elastic.co/t/using-scripts-for-documents-updating/85968/11 "2017-06-20T06:45:49Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
