# Scripting "contains" integer versus long

**URL:** https://discuss.elastic.co/t/scripting-contains-integer-versus-long/23606
**Category:** Elasticsearch
**Created:** [May 11, 2015, 2:08pm UTC](https://discuss.elastic.co/t/scripting-contains-integer-versus-long/23606 "2015-05-11T14:08:24Z")
**Posts on this page:** 4
**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: [May 11, 2015, 2:08pm UTC](https://discuss.elastic.co/t/scripting-contains-integer-versus-long/23606/1 "2015-05-11T14:08:24Z")

</div>

I have a mvel script (groovy looks the same) as follows:  
if (!ctx.\_source.list.contains(document)) {ctx.\_source.list +=  
document;} else {ctx.op = "none"}";

I have a java map  
map.put("id", 100L);

When I try to match the above document to an existing ES document it will  
fail because it's a "long".  
If both documents are "long" like above the match fails. Mapping doesn't  
matter (mapping field with long will still fail)

Using java integer works ie  
map.put("id", 100);

It seems the scripts (mvel and groovy) cast the number to integer before  
doing the match (?)

This is okay for now but if my numbers exceed the java integer max I will  
need a solution.

Regards,

## -- Please update your bookmarks! We have moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)

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/939d94b5-55b7-4e62-9b20-2f60bf7fdf1f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/939d94b5-55b7-4e62-9b20-2f60bf7fdf1f%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: [May 11, 2015, 2:15pm UTC](https://discuss.elastic.co/t/scripting-contains-integer-versus-long/23606/2 "2015-05-11T14:15:50Z")

</div>

I suspect at that point they'll pop out as Longs. Its just my suspicion. I  
haven't read that bit of the code.  
On May 11, 2015 10:08 AM, [eunever32@gmail.com](mailto:eunever32@gmail.com) wrote:

> I have a mvel script (groovy looks the same) as follows:  
> if (!ctx.\_source.list.contains(document)) {ctx.\_source.list +=  
> document;} else {ctx.op = "none"}";
> 
> I have a java map  
> map.put("id", 100L);
> 
> When I try to match the above document to an existing ES document it will  
> fail because it's a "long".  
> If both documents are "long" like above the match fails. Mapping doesn't  
> matter (mapping field with long will still fail)
> 
> Using java integer works ie  
> map.put("id", 100);
> 
> It seems the scripts (mvel and groovy) cast the number to integer before  
> doing the match (?)
> 
> This is okay for now but if my numbers exceed the java integer max I will  
> need a solution.
> 
> Regards,
> 
> ## -- Please update your bookmarks! We have moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)
> 
> 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/939d94b5-55b7-4e62-9b20-2f60bf7fdf1f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/939d94b5-55b7-4e62-9b20-2f60bf7fdf1f%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/939d94b5-55b7-4e62-9b20-2f60bf7fdf1f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/939d94b5-55b7-4e62-9b20-2f60bf7fdf1f%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

## -- Please update your bookmarks! We have moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)

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/CAPmjWd33B1KG24%2BFfMKm6DhoX2jWYg0jqcZgftcFyWmCiHWx3g%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd33B1KG24%2BFfMKm6DhoX2jWYg0jqcZgftcFyWmCiHWx3g%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [May 21, 2015, 1:26pm UTC](https://discuss.elastic.co/t/scripting-contains-integer-versus-long/23606/3 "2015-05-21T13:26:33Z")

</div>

I see there are no answers yet. Any help appreciated.

But just to repeat the question:

the mvel script fails to match documents  
I have a list in elasticsearch containing longs.  
I submit one element in mvel script like this if  
(document.contains(element)) { ... }  
But it never matches.

If I change my document to integer then the script starts to work.

This means the script requires integer to work  
So even though things are working now, if my ES data goes above 2\*32 then  
the application won't work !

On Monday, May 11, 2015 at 3:16:01 PM UTC+1, Nikolas Everett wrote:

> I suspect at that point they'll pop out as Longs. Its just my suspicion. I  
> haven't read that bit of the code.  
> On May 11, 2015 10:08 AM, \<[eune...@gmail.com](mailto:eune...@gmail.com) \<javascript:\>\> wrote:
> 
> > I have a mvel script (groovy looks the same) as follows:  
> > if (!ctx.\_source.list.contains(document)) {ctx.\_source.list +=  
> > document;} else {ctx.op = "none"}";
> > 
> > I have a java map  
> > map.put("id", 100L);
> > 
> > When I try to match the above document to an existing ES document it will  
> > fail because it's a "long".  
> > If both documents are "long" like above the match fails. Mapping doesn't  
> > matter (mapping field with long will still fail)
> > 
> > Using java integer works ie  
> > map.put("id", 100);
> > 
> > It seems the scripts (mvel and groovy) cast the number to integer before  
> > doing the match (?)
> > 
> > This is okay for now but if my numbers exceed the java integer max I will  
> > need a solution.
> > 
> > Regards,
> > 
> > ## -- Please update your bookmarks! We have moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)
> > 
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/939d94b5-55b7-4e62-9b20-2f60bf7fdf1f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/939d94b5-55b7-4e62-9b20-2f60bf7fdf1f%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/939d94b5-55b7-4e62-9b20-2f60bf7fdf1f%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/939d94b5-55b7-4e62-9b20-2f60bf7fdf1f%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

## -- Please update your bookmarks! We have moved to [https://discuss.elastic.co/](https://discuss.elastic.co/)

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/04b1d166-49e4-4414-a1d5-3709449118ef%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/04b1d166-49e4-4414-a1d5-3709449118ef%40googlegroups.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, 12:12am UTC](https://discuss.elastic.co/t/scripting-contains-integer-versus-long/23606/4 "2017-07-06T00:12:39Z")

</div>


