# Remove a field from the document is not successful

**URL:** https://discuss.elastic.co/t/remove-a-field-from-the-document-is-not-successful/47066
**Category:** Elasticsearch
**Created:** [April 12, 2016, 3:08am UTC](https://discuss.elastic.co/t/remove-a-field-from-the-document-is-not-successful/47066 "2016-04-12T03:08:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![szcountryboy](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@szcountryboy](https://discuss.elastic.co/u/szcountryboy)
#### Post date: [April 12, 2016, 3:08am UTC](https://discuss.elastic.co/t/remove-a-field-from-the-document-is-not-successful/47066/1 "2016-04-12T03:08:31Z")

</div>

Hi, I reference

> curl -XPOST 'localhost:9200/test/type1/1/\_update' -d '{  
> "script" : "ctx.\_source.remove("name\_of\_field")"  
> }'

Test document inside the type below the message field to delete

> curl -XPOST 'localhost:9200/test/type/\_update' -d '{  
> "script" : "ctx.\_source.remove("message")"  
> }

> ```
> "script" : "ctx.type.remove(\"message\")"
> "script" : "test.type.remove(\"message\")"
> "script" : "type.remove(\"message\")"
> "script" : "remove(\"message\")"
> 
> ```

But they are not successful, will add the script field .

Thanks.

---

<div class="post-metadata">

### Author: ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)
#### Post date: [April 12, 2016, 9:35am UTC](https://discuss.elastic.co/t/remove-a-field-from-the-document-is-not-successful/47066/2 "2016-04-12T09:35:09Z")

</div>

Hi,

you need to specify the document id in the path. Otherwise you create a new document with the id "\_update".

First of all, turn on dynamic scripting by adding the following line to your elasticsearch.yml and restart the server:

```auto
script.inline: true

```

Here's a complete example:

Insert a document:

```auto
POST /delete-example/type/1
{
    "host": "localhost",
    "field": "delete me"
}

```

The resulting document:

```auto
GET /delete-example/type/1

```

```auto
{
   "_index": "delete-example",
   "_type": "type",
   "_id": "1",
   "_version": 1,
   "_shards": {
      "total": 2,
      "successful": 1,
      "failed": 0
   },
   "created": true
}

```

Delete the field "field":

```auto
POST /delete-example/type/1/_update
{
"script" : "ctx._source.remove(\"field\")"
}

```

The resulting document (note that the field "field" is gone).

```auto
GET /delete-example/type/1

```

```auto
{
   "_index": "delete-example",
   "_type": "type",
   "_id": "1",
   "_version": 2,
   "found": true,
   "_source": {
      "host": "localhost"
   }
}

```

If you want to remove the same field for multiple documents, you should look at the [delete-by-query plugin](https://www.elastic.co/guide/en/elasticsearch/plugins/current/plugins-delete-by-query.html).

Daniel

---

<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: [July 5, 2017, 11:00pm UTC](https://discuss.elastic.co/t/remove-a-field-from-the-document-is-not-successful/47066/3 "2017-07-05T23:00:18Z")

</div>


