# How to set script parameter type

**URL:** <https://discuss.elastic.co/t/how-to-set-script-parameter-type/4798>\
**Category:** Elasticsearch\
**Created:** [July 6, 2011, 11:08pm UTC](https://discuss.elastic.co/t/how-to-set-script-parameter-type/4798 "2011-07-06T23:08:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![George\_3](https://avatars.discourse-cdn.com/v4/letter/g/ecae2f/32.png) [@George\_3](https://discuss.elastic.co/u/George_3)\
**Post date:** [July 6, 2011, 11:08pm UTC](https://discuss.elastic.co/t/how-to-set-script-parameter-type/4798/1 "2011-07-06T23:08:54Z")

</div>

Hi all,

I hope someone would be able to shed light into the problem I am  
experiencing.

I am having trouble with trying to set the "type" of "params" in a  
script, so that they match the type in the mapping.

## For the following type mapping:

{  
"book": {  
"properties": {  
"FileName": { "filter": ["lowercase"], "type": "string" },  
"Members": { "type": "long", "null\_value": 0, "store" : "yes" },  
"Blacklist": { "type": "long", "null\_value": 0, "store" :  
"yes" }  
}  
}  
}

## I use the following script in a query:

"script": {  
"script": "(((doc['Members'] & fieldValue)!=0) AND  
((doc['Blacklist'] & fieldValue)==0))",  
"params": { "fieldValue": -1 }  
}

## I kept on getting type mismatch error.

RuntimeException[could not perform numeric operation on non-numeric  
types: left-  
type=org.elasticsearch.index.field.data.longs.LongDocFieldData; right-  
type=java.lang.Integer [vals  
(org.elasticsearch.index.field.data.longs.LongDocFieldData@1e91c40,  
-1) operation=BIT\_AND (opcode:6) ]]

---

<div class="post-metadata">

**Author:** ![George\_3](https://avatars.discourse-cdn.com/v4/letter/g/ecae2f/32.png) [@George\_3](https://discuss.elastic.co/u/George_3)\
**Post date:** [July 7, 2011, 12:10am UTC](https://discuss.elastic.co/t/how-to-set-script-parameter-type/4798/2 "2011-07-07T00:10:07Z")

</div>

Never mind, I had solved the issue.

for those who might had the same issue,  
the mapping should just state:

"Members": { "type": "integer"}

On Jul 7, 9:08 am, George [gershwinlu...@gmail.com](mailto:gershwinlu...@gmail.com) wrote:

> Hi all,
> 
> I hope someone would be able to shed light into the problem I am  
> experiencing.
> 
> I am having trouble with trying to set the "type" of "params" in a  
> script, so that they match the type in the mapping.
> 
> ## For the following type mapping:
> 
> {  
> "book": {  
> "properties": {  
> "FileName": { "filter": ["lowercase"], "type": "string" },  
> "Members": { "type": "long", "null\_value": 0, "store" : "yes" },  
> "Blacklist": { "type": "long", "null\_value": 0, "store" :  
> "yes" }  
> }  
> }
> 
> }
> 
> ## I use the following script in a query:
> 
> "script": {  
> "script": "(((doc['Members'] & fieldValue)!=0) AND  
> ((doc['Blacklist'] & fieldValue)==0))",  
> "params": { "fieldValue": -1 }
> 
> }
> 
> ## I kept on getting type mismatch error.
> 
> RuntimeException[could not perform numeric operation on non-numeric  
> types: left-  
> type=org.elasticsearch.index.field.data.longs.LongDocFieldData; right-  
> type=java.lang.Integer [vals  
> (org.elasticsearch.index.field.data.longs.LongDocFieldData@1e91c40,  
> -1) operation=BIT\_AND (opcode:6) ]]

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [July 7, 2011, 2:34pm UTC](https://discuss.elastic.co/t/how-to-set-script-parameter-type/4798/3 "2011-07-07T14:34:13Z")

</div>

I am not sure that this is your problem, I think the problem is: doc['field\_name'].value (note calling value at the end).

On Thursday, July 7, 2011 at 3:10 AM, George wrote:

> Never mind, I had solved the issue.
> 
> for those who might had the same issue,  
> the mapping should just state:
> 
> "Members": { "type": "integer"}
> 
> On Jul 7, 9:08 am, George \<[gershwinlu...@gmail.com](mailto:gershwinlu...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> 
> > Hi all,
> > 
> > I hope someone would be able to shed light into the problem I am  
> > experiencing.
> > 
> > I am having trouble with trying to set the "type" of "params" in a  
> > script, so that they match the type in the mapping.
> > 
> > ## For the following type mapping:
> > 
> > {  
> > "book": {  
> > "properties": {  
> > "FileName": { "filter": ["lowercase"], "type": "string" },  
> > "Members": { "type": "long", "null\_value": 0, "store" : "yes" },  
> > "Blacklist": { "type": "long", "null\_value": 0, "store" :  
> > "yes" }  
> > }  
> > }
> > 
> > }
> > 
> > ## I use the following script in a query:
> > 
> > "script": {  
> > "script": "(((doc['Members'] & fieldValue)!=0) AND  
> > ((doc['Blacklist'] & fieldValue)==0))",  
> > "params": { "fieldValue": -1 }
> > 
> > }
> > 
> > ## I kept on getting type mismatch error.
> > 
> > RuntimeException[could not perform numeric operation on non-numeric  
> > types: left-  
> > type=org.elasticsearch.index.field.data.longs.LongDocFieldData; right-  
> > type=java.lang.Integer [vals  
> > (org.elasticsearch.index.field.data.longs.LongDocFieldData@1e91c40,  
> > -1) operation=BIT\_AND (opcode:6) ]]

---

<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, 4:01am UTC](https://discuss.elastic.co/t/how-to-set-script-parameter-type/4798/4 "2017-07-06T04:01:26Z")

</div>


