# List append mvel

**URL:** <https://discuss.elastic.co/t/list-append-mvel/19948>\
**Category:** Elasticsearch\
**Created:** [September 24, 2014, 3:06pm UTC](https://discuss.elastic.co/t/list-append-mvel/19948 "2014-09-24T15:06:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eunever32](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@eunever32](https://discuss.elastic.co/u/eunever32)\
**Post date:** [September 24, 2014, 3:06pm UTC](https://discuss.elastic.co/t/list-append-mvel/19948/1 "2014-09-24T15:06:41Z")

</div>

Hi

I can append to a list as follows:

PUT twitter/tweet/1  
{  
"list": [  
{  
"tweet\_id": "1",  
"a": "b"  
},  
{  
"tweet\_id": "123",  
"a": "f"  
}  
]  
}

POST twitter/tweet/1/\_update  
{  
"script":  
"if (!ctx.\_source.list.contains(newfileinfo)){ctx.\_source.list +=  
newfileinfo}",  
"params": {"newfileinfo": {"tweet\_id": "3", "a": "g"}}  
}

When I run the second step above repeatedly the json : {"tweet\_id": "3",  
"a": "g"} is not inserted which is correct.

However the version keeps changing  
"\_version": 2,  
"\_version": 3,  
"\_version": 4,  
"\_version": 5,  
etc

It is concerning me that the mvel:

- 

```
 "if (!ctx._source.list.contains(newfileinfo)) *{

```

is not working (?)

And the update is happening repeatedly and maybe what's happening is the  
fragment is overwriting the document each time?

That would have performance implications ?

Thanks.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9e615825-38dd-479c-bc7e-af5f8905b876%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9e615825-38dd-479c-bc7e-af5f8905b876%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [September 24, 2014, 3:20pm UTC](https://discuss.elastic.co/t/list-append-mvel/19948/2 "2014-09-24T15:20:18Z")

</div>

Elasticsearch will perform the write even if the document hasn't changed  
unless you set ctx.op to "noop".

Beside the point: you should try using groovy scripting! Its a less funky  
language and it seems to be more stable - like there aren't unexplained  
scripting errors.

On Wed, Sep 24, 2014 at 11:06 AM, [eunever32@gmail.com](mailto:eunever32@gmail.com) wrote:

> Hi
> 
> I can append to a list as follows:
> 
> PUT twitter/tweet/1  
> {  
> "list": [  
> {  
> "tweet\_id": "1",  
> "a": "b"  
> },  
> {  
> "tweet\_id": "123",  
> "a": "f"  
> }  
> ]  
> }
> 
> POST twitter/tweet/1/\_update  
> {  
> "script":  
> "if (!ctx.\_source.list.contains(newfileinfo)){ctx.\_source.list +=  
> newfileinfo}",  
> "params": {"newfileinfo": {"tweet\_id": "3", "a": "g"}}  
> }
> 
> When I run the second step above repeatedly the json : {"tweet\_id": "3",  
> "a": "g"} is not inserted which is correct.
> 
> However the version keeps changing  
> "\_version": 2,  
> "\_version": 3,  
> "\_version": 4,  
> "\_version": 5,  
> etc
> 
> It is concerning me that the mvel:
> 
> - 
> 
> ```
> "if (!ctx._source.list.contains(newfileinfo)) *{
> 
> ```
> 
> is not working (?)
> 
> And the update is happening repeatedly and maybe what's happening is the  
> fragment is overwriting the document each time?
> 
> That would have performance implications ?
> 
> Thanks.
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/9e615825-38dd-479c-bc7e-af5f8905b876%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9e615825-38dd-479c-bc7e-af5f8905b876%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/9e615825-38dd-479c-bc7e-af5f8905b876%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/9e615825-38dd-479c-bc7e-af5f8905b876%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAPmjWd2\_xWowdc%3DLJkCy5A8hzVFfSsZxCxkom%3DckXzrEegh2HQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd2_xWowdc%3DLJkCy5A8hzVFfSsZxCxkom%3DckXzrEegh2HQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:00am UTC](https://discuss.elastic.co/t/list-append-mvel/19948/3 "2017-07-06T01:00:09Z")

</div>


