# Accessing Parameter values inside a MVEL script

**URL:** <https://discuss.elastic.co/t/accessing-parameter-values-inside-a-mvel-script/17541>\
**Category:** Elasticsearch\
**Created:** [May 15, 2014, 4:26pm UTC](https://discuss.elastic.co/t/accessing-parameter-values-inside-a-mvel-script/17541 "2014-05-15T16:26:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ravimbhatt](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@ravimbhatt](https://discuss.elastic.co/u/ravimbhatt)\
**Post date:** [May 15, 2014, 4:26pm UTC](https://discuss.elastic.co/t/accessing-parameter-values-inside-a-mvel-script/17541/1 "2014-05-15T16:26:49Z")

</div>

Hi All,

I am trying to run a faceted query with a custom script on the facet value.  
I need to pass a "map" of values into the script with params. Below id my  
_script_,

"_value\_script_":"( iid1= new String(doc['itemid1'].value) ;r =  
doc['similarity'].value \* srcVals.containsKey(iid1) ? srcVals.get(iid1): -1  
; return r )"

For some reason, my _containsKey_ returns true but get on the map results  
in a _nullpointer_ exception.

I pass params as :

"_params_": { "srcVals": sources }

Where sources is a python dict. example dict is:

{'3058211': '3', '3473092': '4', '3097044': '3', '2491239': '4', '2371363':  
'4', '3049884': '5', '2212351': '4', '3064057': '3'}

As you can see, i need to get a number associated with some other number. I  
pass the association as a param. but accessing the param is returning a  
nullpointer.

Thanks!  
Ravi

--  
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/31746a14-4c9c-4fe3-b8f2-c59947f31706%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/31746a14-4c9c-4fe3-b8f2-c59947f31706%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![ravimbhatt](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@ravimbhatt](https://discuss.elastic.co/u/ravimbhatt)\
**Post date:** [May 15, 2014, 4:35pm UTC](https://discuss.elastic.co/t/accessing-parameter-values-inside-a-mvel-script/17541/2 "2014-05-15T16:35:52Z")

</div>

Here is my full ES query in python

res1 = es.search(index="myIndex", body={"query":{ "bool": { "must" : {  
"terms":{ "type.itemid1":wiids } }, "must\_not" : { "terms" : {  
"type.itemid2":wiids } } } },"facets":{ "itemid2Stats": {"terms\_stats" : {  
"key\_field": "type.itemid2", "value\_script":"( iid1=  
doc['itemid1'].value;r = doc['internalScore'].value \*  
srcVals.containsKey(iid1) ? srcVals.get(iid1): 11; return r )", "params": {  
"srcVals": sources }, "size": 1000, "shard\_size": 5000 ,"order": "mean"  
} } }}, sort=["type.itemid1:desc","type.similarity:desc"], size=1)

and the error i get is:

sort[\<custom:"itemid1":  
org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@64f6e93\>!,\<custom:"similarity":  
org.elasticsearch.index.fielddata.fieldcomparator.FloatValuesComparatorSource@48e47821\>!]:  
Query Failed [Failed to execute main query]]; nested: NullPointerException;  
}

On Thursday, 15 May 2014 17:26:49 UTC+1, [ravim...@gmail.com](mailto:ravim...@gmail.com) wrote:

> Hi All,
> 
> I am trying to run a faceted query with a custom script on the facet  
> value. I need to pass a "map" of values into the script with params. Below  
> id my _script_,
> 
> "_value\_script_":"( iid1= new String(doc['itemid1'].value) ;r =  
> doc['similarity'].value \* srcVals.containsKey(iid1) ? srcVals.get(iid1): -1  
> ; return r )"
> 
> For some reason, my _containsKey_ returns true but get on the map results  
> in a _nullpointer_ exception.
> 
> I pass params as :
> 
> "_params_": { "srcVals": sources }
> 
> Where sources is a python dict. example dict is:
> 
> {'3058211': '3', '3473092': '4', '3097044': '3', '2491239': '4',  
> '2371363': '4', '3049884': '5', '2212351': '4', '3064057': '3'}
> 
> As you can see, i need to get a number associated with some other number.  
> I pass the association as a param. but accessing the param is returning a  
> nullpointer.
> 
> Thanks!  
> Ravi

--  
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/d7753b14-c793-4c45-8aec-ac0fd1b386f9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d7753b14-c793-4c45-8aec-ac0fd1b386f9%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![ravimbhatt](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@ravimbhatt](https://discuss.elastic.co/u/ravimbhatt)\
**Post date:** [May 19, 2014, 1:03pm UTC](https://discuss.elastic.co/t/accessing-parameter-values-inside-a-mvel-script/17541/3 "2014-05-19T13:03:41Z")

</div>

Hi All,

Any help on this please? Has anyone tried MVEL based scripts that get a  
value out of a map?

Thanks!  
Ravi

On Thursday, 15 May 2014 17:35:52 UTC+1, [ravim...@gmail.com](mailto:ravim...@gmail.com) wrote:

> Here is my full ES query in python
> 
> res1 = es.search(index="myIndex", body={"query":{ "bool": { "must" : {  
> "terms":{ "type.itemid1":wiids } }, "must\_not" : { "terms" : {  
> "type.itemid2":wiids } } } },"facets":{ "itemid2Stats": {"terms\_stats" :  
> { "key\_field": "type.itemid2", "value\_script":"( iid1=  
> doc['itemid1'].value;r = doc['internalScore'].value \*  
> srcVals.containsKey(iid1) ? srcVals.get(iid1): 11; return r )", "params":  
> { "srcVals": sources }, "size": 1000, "shard\_size": 5000 ,"order": "mean"  
> } } }}, sort=["type.itemid1:desc","type.similarity:desc"], size=1)
> 
> and the error i get is:
> 
> sort[\<custom:"itemid1":  
> org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@64f6e93\>!,\<custom:"similarity":  
> org.elasticsearch.index.fielddata.fieldcomparator.FloatValuesComparatorSource@48e47821\>!]:  
> Query Failed [Failed to execute main query]]; nested: NullPointerException;  
> }
> 
> On Thursday, 15 May 2014 17:26:49 UTC+1, [ravim...@gmail.com](mailto:ravim...@gmail.com) wrote:
> 
> > Hi All,
> > 
> > I am trying to run a faceted query with a custom script on the facet  
> > value. I need to pass a "map" of values into the script with params. Below  
> > id my _script_,
> > 
> > "_value\_script_":"( iid1= new String(doc['itemid1'].value) ;r =  
> > doc['similarity'].value \* srcVals.containsKey(iid1) ? srcVals.get(iid1): -1  
> > ; return r )"
> > 
> > For some reason, my _containsKey_ returns true but get on the map  
> > results in a _nullpointer_ exception.
> > 
> > I pass params as :
> > 
> > "_params_": { "srcVals": sources }
> > 
> > Where sources is a python dict. example dict is:
> > 
> > {'3058211': '3', '3473092': '4', '3097044': '3', '2491239': '4',  
> > '2371363': '4', '3049884': '5', '2212351': '4', '3064057': '3'}
> > 
> > As you can see, i need to get a number associated with some other number.  
> > I pass the association as a param. but accessing the param is returning a  
> > nullpointer.
> > 
> > Thanks!  
> > Ravi

--  
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/3e1051d7-c385-4436-b24a-b3183d904818%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3e1051d7-c385-4436-b24a-b3183d904818%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, 1:28am UTC](https://discuss.elastic.co/t/accessing-parameter-values-inside-a-mvel-script/17541/4 "2017-07-06T01:28:30Z")

</div>


