# How to write better scripts with MVEL

**URL:** https://discuss.elastic.co/t/how-to-write-better-scripts-with-mvel/11819
**Category:** Elasticsearch
**Created:** [May 5, 2013, 10:51am UTC](https://discuss.elastic.co/t/how-to-write-better-scripts-with-mvel/11819 "2013-05-05T10:51:38Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Arjit\_Gupta](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Arjit\_Gupta](https://discuss.elastic.co/u/Arjit_Gupta)
#### Post date: [May 5, 2013, 10:51am UTC](https://discuss.elastic.co/t/how-to-write-better-scripts-with-mvel/11819/1 "2013-05-05T10:51:38Z")

</div>

Hi,

I am trying to write script which updates a document ( deleting some fields  
).  
The script is ctx.\_source.remove("title") this allows us to delete on  
field named title.  
How do I change the script to delete multiple fields.  
Where Can I read more about the script. I have one of the resource as  
[http://www.elasticsearch.org/guide/reference/api/update/](http://www.elasticsearch.org/guide/reference/api/update/)

Thanks in advance.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [May 5, 2013, 11:02am UTC](https://discuss.elastic.co/t/how-to-write-better-scripts-with-mvel/11819/2 "2013-05-05T11:02:18Z")

</div>

Does something like the following work?

ctx.\_source.remove("title");ctx.\_source.remove("summary");

## HTH

David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 5 mai 2013 à 12:51, Arjit Gupta [arjit292@gmail.com](mailto:arjit292@gmail.com) a écrit :

> ctx.\_source.remove("title"

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Arjit\_Gupta](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Arjit\_Gupta](https://discuss.elastic.co/u/Arjit_Gupta)
#### Post date: [May 5, 2013, 1:51pm UTC](https://discuss.elastic.co/t/how-to-write-better-scripts-with-mvel/11819/3 "2013-05-05T13:51:55Z")

</div>

ctx.\_source.remove("title");ctx.\_source.remove("summary");  
Works well. But I was looking for something like  
ctx.\_source.removeAll({"title","summary"});  
The number of fields can be any number, I know can concat the script that  
many times and it will work.

Thanks ,  
Arjit

On Sun, May 5, 2013 at 4:32 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Does something like the following work?
> 
> ctx.\_source.remove("title");ctx.\_source.remove("summary");
> 
> ## HTH
> 
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 5 mai 2013 à 12:51, Arjit Gupta [arjit292@gmail.com](mailto:arjit292@gmail.com) a écrit :
> 
> > ctx.\_source.remove("title"
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/QDVIPOpqRhw/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/QDVIPOpqRhw/unsubscribe?hl=en-US)  
> .  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![sujoysett](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@sujoysett](https://discuss.elastic.co/u/sujoysett)
#### Post date: [May 6, 2013, 5:54am UTC](https://discuss.elastic.co/t/how-to-write-better-scripts-with-mvel/11819/4 "2013-05-06T05:54:29Z")

</div>

Using a loop might help.

{  
"script": "foreach(var1 : tag1) { ctx.\_source.remove(var1); }",  
"params": {  
"tag1": [  
"title",  
"summary",  
"nextfield"  
]  
}  
}

U can keep updating the params as per the requirement.

-- Sujoy.

On Sunday, May 5, 2013 7:21:55 PM UTC+5:30, Arjit Gupta wrote:

> ctx.\_source.remove("title");ctx.\_source.remove("summary");  
> Works well. But I was looking for something like  
> ctx.\_source.removeAll({"title","summary"});  
> The number of fields can be any number, I know can concat the script that  
> many times and it will work.
> 
> Thanks ,  
> Arjit
> 
> On Sun, May 5, 2013 at 4:32 PM, David Pilato \<[da...@pilato.fr](mailto:da...@pilato.fr)\<javascript:\>
> 
> > wrote:
> 
> > Does something like the following work?
> > 
> > ctx.\_source.remove("title");ctx.\_source.remove("summary");
> > 
> > ## HTH
> > 
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 5 mai 2013 à 12:51, Arjit Gupta \<[arji...@gmail.com](mailto:arji...@gmail.com) \<javascript:\>\> a  
> > écrit :
> > 
> > > ctx.\_source.remove("title"
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/QDVIPOpqRhw/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/QDVIPOpqRhw/unsubscribe?hl=en-US)  
> > .  
> > To unsubscribe from this group and all its topics, send an email to  
> > [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Arjit\_Gupta](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Arjit\_Gupta](https://discuss.elastic.co/u/Arjit_Gupta)
#### Post date: [May 7, 2013, 7:31am UTC](https://discuss.elastic.co/t/how-to-write-better-scripts-with-mvel/11819/5 "2013-05-07T07:31:23Z")

</div>

Thanks a lot. Thats what I wanted. Can I know the where i can learn more  
on it

Thanks ,  
Arjit

On Mon, May 6, 2013 at 11:24 AM, Sujoy Sett [sujoysett@gmail.com](mailto:sujoysett@gmail.com) wrote:

> Using a loop might help.
> 
> {  
> "script": "foreach(var1 : tag1) { ctx.\_source.remove(var1); }",  
> "params": {  
> "tag1": [  
> "title",  
> "summary",  
> "nextfield"  
> ]  
> }  
> }
> 
> U can keep updating the params as per the requirement.
> 
> -- Sujoy.
> 
> On Sunday, May 5, 2013 7:21:55 PM UTC+5:30, Arjit Gupta wrote:
> 
> > ctx.\_source.remove("title");**ctx.\_source.remove("summary");  
> > Works well. But I was looking for something like  
> > ctx.\_source.removeAll({"title"**,"summary"});  
> > The number of fields can be any number, I know can concat the script that  
> > many times and it will work.
> > 
> > Thanks ,  
> > Arjit
> > 
> > On Sun, May 5, 2013 at 4:32 PM, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> > 
> > > Does something like the following work?
> > > 
> > > ctx.\_source.remove("title");\*\*ctx.\_source.remove("summary");
> > > 
> > > ## HTH
> > > 
> > > David 😉  
> > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > 
> > > Le 5 mai 2013 à 12:51, Arjit Gupta [arji...@gmail.com](mailto:arji...@gmail.com) a écrit :
> > > 
> > > > ctx.\_source.remove("title"
> > > 
> > > --  
> > > You received this message because you are subscribed to a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit [https://groups.google.com/d/](https://groups.google.com/d/)\*\*  
> > > topic/elasticsearch/\*\*QDVIPOpqRhw/unsubscribe?hl=en-\*\*US[https://groups.google.com/d/topic/elasticsearch/QDVIPOpqRhw/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/QDVIPOpqRhw/unsubscribe?hl=en-US)  
> > > .  
> > > To unsubscribe from this group and all its topics, send an email to  
> > > elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > 
> > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > .
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/QDVIPOpqRhw/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/QDVIPOpqRhw/unsubscribe?hl=en-US)  
> > .  
> > To unsubscribe from this group and all its topics, send an email to  
> > [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![sujoysett](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@sujoysett](https://discuss.elastic.co/u/sujoysett)
#### Post date: [May 7, 2013, 8:28am UTC](https://discuss.elastic.co/t/how-to-write-better-scripts-with-mvel/11819/6 "2013-05-07T08:28:05Z")

</div>

u can try the official guide [http://mvel.codehaus.org/Language+Guide+for+2.0](http://mvel.codehaus.org/Language+Guide+for+2.0)

-- Sujoy.

On Tuesday, May 7, 2013 1:01:23 PM UTC+5:30, Arjit Gupta wrote:

> Thanks a lot. Thats what I wanted. Can I know the where i can learn more  
> on it
> 
> Thanks ,  
> Arjit
> 
> On Mon, May 6, 2013 at 11:24 AM, Sujoy Sett \<[sujo...@gmail.com](mailto:sujo...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Using a loop might help.
> > 
> > {  
> > "script": "foreach(var1 : tag1) { ctx.\_source.remove(var1); }",  
> > "params": {  
> > "tag1": [  
> > "title",  
> > "summary",  
> > "nextfield"  
> > ]  
> > }  
> > }
> > 
> > U can keep updating the params as per the requirement.
> > 
> > -- Sujoy.
> > 
> > On Sunday, May 5, 2013 7:21:55 PM UTC+5:30, Arjit Gupta wrote:
> > 
> > > ctx.\_source.remove("title");**ctx.\_source.remove("summary");  
> > > Works well. But I was looking for something like  
> > > ctx.\_source.removeAll({"title"**,"summary"});  
> > > The number of fields can be any number, I know can concat the script  
> > > that many times and it will work.
> > > 
> > > Thanks ,  
> > > Arjit
> > > 
> > > On Sun, May 5, 2013 at 4:32 PM, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:
> > > 
> > > > Does something like the following work?
> > > > 
> > > > ctx.\_source.remove("title");\*\*ctx.\_source.remove("summary");
> > > > 
> > > > ## HTH
> > > > 
> > > > David 😉  
> > > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > > 
> > > > Le 5 mai 2013 à 12:51, Arjit Gupta [arji...@gmail.com](mailto:arji...@gmail.com) a écrit :
> > > > 
> > > > > ctx.\_source.remove("title"
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to a topic in the  
> > > > Google Groups "elasticsearch" group.  
> > > > To unsubscribe from this topic, visit [https://groups.google.com/d/](https://groups.google.com/d/)\*\*  
> > > > topic/elasticsearch/\*\*QDVIPOpqRhw/unsubscribe?hl=en-\*\*US[https://groups.google.com/d/topic/elasticsearch/QDVIPOpqRhw/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/QDVIPOpqRhw/unsubscribe?hl=en-US)  
> > > > .  
> > > > To unsubscribe from this group and all its topics, send an email to  
> > > > elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > > 
> > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > .
> > > 
> > > --  
> > > You received this message because you are subscribed to a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit  
> > > [https://groups.google.com/d/topic/elasticsearch/QDVIPOpqRhw/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/QDVIPOpqRhw/unsubscribe?hl=en-US)  
> > > .  
> > > To unsubscribe from this group and all its topics, send an email to  
> > > [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:37am UTC](https://discuss.elastic.co/t/how-to-write-better-scripts-with-mvel/11819/7 "2017-07-06T02:37:58Z")

</div>


