# Mvel and data types

**URL:** <https://discuss.elastic.co/t/mvel-and-data-types/9905>\
**Category:** Elasticsearch\
**Created:** [November 30, 2012, 4:46pm UTC](https://discuss.elastic.co/t/mvel-and-data-types/9905 "2012-11-30T16:46:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Weitzenfeld](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_weitzenfeld/32/2593_2.png) [@Daniel\_Weitzenfeld](https://discuss.elastic.co/u/Daniel_Weitzenfeld)\
**Post date:** [November 30, 2012, 4:46pm UTC](https://discuss.elastic.co/t/mvel-and-data-types/9905/1 "2012-11-30T16:46:06Z")

</div>

When I use an mvel script on a field I've mapped as byte, I get an error,  
below.  
When I changed my mvel script from  
doc['age'].value\>param3 ? .....  
to  
doc['age'].doubleValue\>param3 ? .....

The error went away.

Questions:

1. Can I tweak my mvel script so that I don't need to convert from byte?  
Should I convert my parameter to byte? If so, how/where?
2. What is the best practice here?

The error:

[2012-11-30 11:37:11,093][DEBUG][action.search.type] [Algrim the  
Strong] [haw\_index][2], node[Dz4WxCv0TdKyZiodaEepRg], [P], s[STARTED]:  
Failed to execute [org.elasticsearch.action.search.SearchRequest@1599f755]  
org.elasticsearch.search.query.QueryPhaseExecutionException:  
[haw\_index][2]: ..... .....: Query Failed [Failed to  
execute main query]  
at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:198)  
at  
org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:234)  
at  
org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:140)  
at  
org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:80)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:204)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:191)  
at  
org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:177)  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
at java.lang.Thread.run(Thread.java:619)  
Caused by: [Error: internal error: 113]  
[Near : {... doc['age'].value\>param3 ? pow( ....}]  
^  
[Line: 1, Column: 1]  
at  
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:439)  
at  
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:142)  
at  
org.elasticsearch.common.mvel2.optimizers.dynamic.DynamicOptimizer.optimizeAccessor(DynamicOptimizer.java:67)  
at org.elasticsearch.common.mvel2.ast.ASTNode.optimize(ASTNode.java:157)  
at  
org.elasticsearch.common.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:113)  
at  
org.elasticsearch.common.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:116)  
at org.elasticsearch.common.mvel2.MVELRuntime.execute(MVELRuntime.java:85)  
at  
org.elasticsearch.common.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:123)  
at  
org.elasticsearch.common.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:116)  
at  
org.elasticsearch.script.mvel.MvelScriptEngineService$MvelSearchScript.run(MvelScriptEngineService.java:192)  
at  
org.elasticsearch.script.mvel.MvelScriptEngineService$MvelSearchScript.runAsFloat(MvelScriptEngineService.java:197)  
at  
org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction.factor(CustomScoreQueryParser.java:129)  
at  
org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery$CustomBoostFactorScorer.score(FiltersFunctionScoreQuery.java:314)  
at  
org.apache.lucene.search.TopScoreDocCollector$InOrderTopScoreDocCollector.collect(TopScoreDocCollector.java:47)  
at org.apache.lucene.search.Scorer.score(Scorer.java:90)  
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:581)  
at  
org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:195)  
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:445)  
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:426)  
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:342)  
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:330)  
at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:194)  
... 9 more  
Caused by: java.lang.RuntimeException: internal error: 113  
at  
org.elasticsearch.common.mvel2.math.MathProcessor.toType(MathProcessor.java:139)  
at  
org.elasticsearch.common.mvel2.math.MathProcessor.doPrimWrapperArithmetic(MathProcessor.java:90)  
at  
org.elasticsearch.common.mvel2.math.MathProcessor.\_doOperations(MathProcessor.java:214)  
at  
org.elasticsearch.common.mvel2.math.MathProcessor.doOperations(MathProcessor.java:78)  
at  
org.elasticsearch.common.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:116)  
at  
org.elasticsearch.common.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:38)  
at  
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:959)  
at  
org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:343)  
... 30 more

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [November 30, 2012, 6:20pm UTC](https://discuss.elastic.co/t/mvel-and-data-types/9905/2 "2012-11-30T18:20:38Z")

</div>

That might be a MVEL issue. I cannot reproduce it based on the information  
that you have provided: [https://groups.google.com/d/topic/elasticsearch/CddIPlJxvU8/discussion · GitHub](https://gist.github.com/4177476) I suspect that  
the problem might be in the part of the script that you have omitted.  
Judging from the stack trace MVEL is trying to cast something to BYTE and  
fails. It does it while trying to assign something to the byte field. Do  
you have any assignments in this script?

On Friday, November 30, 2012 11:46:06 AM UTC-5, Daniel Weitzenfeld wrote:

> When I use an mvel script on a field I've mapped as byte, I get an error,  
> below.  
> When I changed my mvel script from  
> doc['age'].value\>param3 ? .....  
> to  
> doc['age'].doubleValue\>param3 ? .....
> 
> The error went away.
> 
> Questions:
> 
> 1. Can I tweak my mvel script so that I don't need to convert from byte?  
> Should I convert my parameter to byte? If so, how/where?
> 2. What is the best practice here?
> 
> The error:
> 
> [2012-11-30 11:37:11,093][DEBUG][action.search.type] [Algrim the  
> Strong] [haw\_index][2], node[Dz4WxCv0TdKyZiodaEepRg], [P], s[STARTED]:  
> Failed to execute [org.elasticsearch.action.search.SearchRequest@1599f755]  
> org.elasticsearch.search.query.QueryPhaseExecutionException:  
> [haw\_index][2]: ..... .....: Query Failed [Failed to  
> execute main query]  
> at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:198)  
> at  
> org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:234)  
> at  
> org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:140)  
> at  
> org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:80)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:204)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:191)  
> at  
> org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:177)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
> at  
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
> at java.lang.Thread.run(Thread.java:619)  
> Caused by: [Error: internal error: 113]  
> [Near : {... doc['age'].value\>param3 ? pow( ....}]  
> ^  
> [Line: 1, Column: 1]  
> at  
> org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:439)  
> at  
> org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:142)  
> at  
> org.elasticsearch.common.mvel2.optimizers.dynamic.DynamicOptimizer.optimizeAccessor(DynamicOptimizer.java:67)  
> at org.elasticsearch.common.mvel2.ast.ASTNode.optimize(ASTNode.java:157)  
> at  
> org.elasticsearch.common.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:113)  
> at  
> org.elasticsearch.common.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:116)  
> at org.elasticsearch.common.mvel2.MVELRuntime.execute(MVELRuntime.java:85)  
> at  
> org.elasticsearch.common.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:123)  
> at  
> org.elasticsearch.common.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:116)  
> at  
> org.elasticsearch.script.mvel.MvelScriptEngineService$MvelSearchScript.run(MvelScriptEngineService.java:192)  
> at  
> org.elasticsearch.script.mvel.MvelScriptEngineService$MvelSearchScript.runAsFloat(MvelScriptEngineService.java:197)  
> at  
> org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction.factor(CustomScoreQueryParser.java:129)  
> at  
> org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery$CustomBoostFactorScorer.score(FiltersFunctionScoreQuery.java:314)  
> at  
> org.apache.lucene.search.TopScoreDocCollector$InOrderTopScoreDocCollector.collect(TopScoreDocCollector.java:47)  
> at org.apache.lucene.search.Scorer.score(Scorer.java:90)  
> at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:581)  
> at  
> org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:195)  
> at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:445)  
> at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:426)  
> at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:342)  
> at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:330)  
> at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:194)  
> ... 9 more  
> Caused by: java.lang.RuntimeException: internal error: 113  
> at  
> org.elasticsearch.common.mvel2.math.MathProcessor.toType(MathProcessor.java:139)  
> at  
> org.elasticsearch.common.mvel2.math.MathProcessor.doPrimWrapperArithmetic(MathProcessor.java:90)  
> at  
> org.elasticsearch.common.mvel2.math.MathProcessor.\_doOperations(MathProcessor.java:214)  
> at  
> org.elasticsearch.common.mvel2.math.MathProcessor.doOperations(MathProcessor.java:78)  
> at  
> org.elasticsearch.common.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:116)  
> at  
> org.elasticsearch.common.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:38)  
> at  
> org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:959)  
> at  
> org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:343)  
> ... 30 more

--

---

<div class="post-metadata">

**Author:** ![Daniel\_Weitzenfeld](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_weitzenfeld/32/2593_2.png) [@Daniel\_Weitzenfeld](https://discuss.elastic.co/u/Daniel_Weitzenfeld)\
**Post date:** [November 30, 2012, 7:29pm UTC](https://discuss.elastic.co/t/mvel-and-data-types/9905/3 "2012-11-30T19:29:03Z")

</div>

Thanks for your reply, Igor. I'm sorry about redacting, it's just that the  
custom scoring is a proprietary formula I have to be careful about.

Full script is below. It's from the 'filters' part of a  
'custom\_filters\_score' query...  
{  
"filter": {  
"match\_all":{}  
},  
"script":"doc['age'].value\>param3 ?  
pow(doc['age'].value-param3,2)\*param1 :  
pow(doc['age'].value-param3,2)\*param2"  
}

...and the the relevant bit from the stack trace - I've bolded the relevant  
filter and parameters:

org.elasticsearch.search.query.QueryPhaseExecutionException:  
[haw\_index][0]: query[custom score  
(ConstantScore(NotDeleted(org.elasticsearch.common.lucene.search.AndFilter@6caa4303)),  
functions: [{filter(_:_), function [boost[1000.0]]}_{filter(_:_),_ \*function  
[script[doc['age'].value\>param3 ? pow(doc['age'].value-param3,2)\*param1 :  
pow(doc['age'].value-param3,2)_param2]_, params  
[{\_source=org.elasticsearch.search.lookup.SourceLookup@57615e6, param11=45,  
_param1=0.00383_, param10=-0.07694, _param2=0.00399_, _param3=59_,  
param12=-1.0E-5, param4=1.2, param5=-0.08645, param7=3, param8=-2.44139,  
param9=0, param20=-0.07729,  
\_fields=org.elasticsearch.search.lookup.FieldsLookup@b97b1d7,  
\_doc=org.elasticsearch.search.lookup.DocLookup@141ca033,  
doc=org.elasticsearch.search.lookup.DocLookup@141ca033, param17=0,  
param18=-0.07599, param19=0}]]} ....... from[0],size[207]: Query Failed [Failed to execute main  
query]

Could it be because it's trying to cast param1 and param2 to byte in order  
to multiply them?

On Friday, November 30, 2012 1:20:38 PM UTC-5, Igor Motov wrote:

> That might be a MVEL issue. I cannot reproduce it based on the information  
> that you have provided: [https://groups.google.com/d/topic/elasticsearch/CddIPlJxvU8/discussion · GitHub](https://gist.github.com/4177476) I suspect that  
> the problem might be in the part of the script that you have omitted.  
> Judging from the stack trace MVEL is trying to cast something to BYTE and  
> fails. It does it while trying to assign something to the byte field. Do  
> you have any assignments in this script?
> 
> On Friday, November 30, 2012 11:46:06 AM UTC-5, Daniel Weitzenfeld wrote:
> 
> > When I use an mvel script on a field I've mapped as byte, I get an error,  
> > below.  
> > When I changed my mvel script from  
> > doc['age'].value\>param3 ? .....  
> > to  
> > doc['age'].doubleValue\>param3 ? .....
> > 
> > The error went away.
> > 
> > Questions:
> > 
> > 1. Can I tweak my mvel script so that I don't need to convert from byte?  
> > Should I convert my parameter to byte? If so, how/where?
> > 2. What is the best practice here?
> > 
> > The error:
> > 
> > [2012-11-30 11:37:11,093][DEBUG][action.search.type] [Algrim the  
> > Strong] [haw\_index][2], node[Dz4WxCv0TdKyZiodaEepRg], [P], s[STARTED]:  
> > Failed to execute [org.elasticsearch.action.search.SearchRequest@1599f755]  
> > org.elasticsearch.search.query.QueryPhaseExecutionException:  
> > [haw\_index][2]: ..... .....: Query Failed [Failed to  
> > execute main query]  
> > at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:198)  
> > at  
> > org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:234)  
> > at  
> > org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:140)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:80)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:204)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:191)  
> > at  
> > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:177)  
> > at  
> > java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
> > at  
> > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
> > at java.lang.Thread.run(Thread.java:619)  
> > Caused by: [Error: internal error: 113]  
> > [Near : {... doc['age'].value\>param3 ? pow( ....}]  
> > ^  
> > [Line: 1, Column: 1]  
> > at  
> > org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:439)  
> > at  
> > org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:142)  
> > at  
> > org.elasticsearch.common.mvel2.optimizers.dynamic.DynamicOptimizer.optimizeAccessor(DynamicOptimizer.java:67)  
> > at org.elasticsearch.common.mvel2.ast.ASTNode.optimize(ASTNode.java:157)  
> > at  
> > org.elasticsearch.common.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:113)  
> > at  
> > org.elasticsearch.common.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:116)  
> > at org.elasticsearch.common.mvel2.MVELRuntime.execute(MVELRuntime.java:85)  
> > at  
> > org.elasticsearch.common.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:123)  
> > at  
> > org.elasticsearch.common.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:116)  
> > at  
> > org.elasticsearch.script.mvel.MvelScriptEngineService$MvelSearchScript.run(MvelScriptEngineService.java:192)  
> > at  
> > org.elasticsearch.script.mvel.MvelScriptEngineService$MvelSearchScript.runAsFloat(MvelScriptEngineService.java:197)  
> > at  
> > org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction.factor(CustomScoreQueryParser.java:129)  
> > at  
> > org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery$CustomBoostFactorScorer.score(FiltersFunctionScoreQuery.java:314)  
> > at  
> > org.apache.lucene.search.TopScoreDocCollector$InOrderTopScoreDocCollector.collect(TopScoreDocCollector.java:47)  
> > at org.apache.lucene.search.Scorer.score(Scorer.java:90)  
> > at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:581)  
> > at  
> > org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:195)  
> > at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:445)  
> > at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:426)  
> > at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:342)  
> > at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:330)  
> > at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:194)  
> > ... 9 more  
> > Caused by: java.lang.RuntimeException: internal error: 113  
> > at  
> > org.elasticsearch.common.mvel2.math.MathProcessor.toType(MathProcessor.java:139)  
> > at  
> > org.elasticsearch.common.mvel2.math.MathProcessor.doPrimWrapperArithmetic(MathProcessor.java:90)  
> > at  
> > org.elasticsearch.common.mvel2.math.MathProcessor.\_doOperations(MathProcessor.java:214)  
> > at  
> > org.elasticsearch.common.mvel2.math.MathProcessor.doOperations(MathProcessor.java:78)  
> > at  
> > org.elasticsearch.common.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:116)  
> > at  
> > org.elasticsearch.common.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:38)  
> > at  
> > org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:959)  
> > at  
> > org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:343)  
> > ... 30 more

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [November 30, 2012, 10:58pm UTC](https://discuss.elastic.co/t/mvel-and-data-types/9905/4 "2012-11-30T22:58:05Z")

</div>

Thanks, I can reproduce it now. It fails on doc['age'].value-param3. It  
looks like MVEL just cannot do any arithmetic operations with bytes even if  
both operands are bytes. Try calculating doc['age'].value

- doc['age'].value for example. So, basically, anywhere where byte value is  
used in a formula, you have to convert it to some other numeric type.

On Friday, November 30, 2012 2:29:03 PM UTC-5, Daniel Weitzenfeld wrote:

> Thanks for your reply, Igor. I'm sorry about redacting, it's just that  
> the custom scoring is a proprietary formula I have to be careful about.
> 
> Full script is below. It's from the 'filters' part of a  
> 'custom\_filters\_score' query...  
> {  
> "filter": {  
> "match\_all":{}  
> },  
> "script":"doc['age'].value\>param3 ?  
> pow(doc['age'].value-param3,2)\*param1 :  
> pow(doc['age'].value-param3,2)\*param2"  
> }
> 
> ...and the the relevant bit from the stack trace - I've bolded the  
> relevant filter and parameters:
> 
> org.elasticsearch.search.query.QueryPhaseExecutionException:  
> [haw\_index][0]: query[custom score  
> (ConstantScore(NotDeleted(org.elasticsearch.common.lucene.search.AndFilter@6caa4303)),  
> functions: [{filter(_:_), function [boost[1000.0]]}_{filter(_:_),_ \*function  
> [script[doc['age'].value\>param3 ? pow(doc['age'].value-param3,2)\*param1 :  
> pow(doc['age'].value-param3,2)_param2]_, params  
> [{\_source=org.elasticsearch.search.lookup.SourceLookup@57615e6, param11=45,  
> _param1=0.00383_, param10=-0.07694, _param2=0.00399_, _param3=59_,  
> param12=-1.0E-5, param4=1.2, param5=-0.08645, param7=3, param8=-2.44139,  
> param9=0, param20=-0.07729,  
> \_fields=org.elasticsearch.search.lookup.FieldsLookup@b97b1d7,  
> \_doc=org.elasticsearch.search.lookup.DocLookup@141ca033,  
> doc=org.elasticsearch.search.lookup.DocLookup@141ca033, param17=0,  
> param18=-0.07599, param19=0}]]} ....... from[0],size[207]: Query Failed [Failed to execute main  
> query]
> 
> Could it be because it's trying to cast param1 and param2 to byte in order  
> to multiply them?
> 
> On Friday, November 30, 2012 1:20:38 PM UTC-5, Igor Motov wrote:
> 
> > That might be a MVEL issue. I cannot reproduce it based on the  
> > information that you have provided: [https://groups.google.com/d/topic/elasticsearch/CddIPlJxvU8/discussion · GitHub](https://gist.github.com/4177476) I  
> > suspect that the problem might be in the part of the script that you  
> > have omitted. Judging from the stack trace MVEL is trying to cast something  
> > to BYTE and fails. It does it while trying to assign something to the byte  
> > field. Do you have any assignments in this script?
> > 
> > On Friday, November 30, 2012 11:46:06 AM UTC-5, Daniel Weitzenfeld wrote:
> > 
> > > When I use an mvel script on a field I've mapped as byte, I get an  
> > > error, below.  
> > > When I changed my mvel script from  
> > > doc['age'].value\>param3 ? .....  
> > > to  
> > > doc['age'].doubleValue\>param3 ? .....
> > > 
> > > The error went away.
> > > 
> > > Questions:
> > > 
> > > 1. Can I tweak my mvel script so that I don't need to convert from  
> > > byte? Should I convert my parameter to byte? If so, how/where?
> > > 2. What is the best practice here?
> > > 
> > > The error:
> > > 
> > > [2012-11-30 11:37:11,093][DEBUG][action.search.type] [Algrim the  
> > > Strong] [haw\_index][2], node[Dz4WxCv0TdKyZiodaEepRg], [P], s[STARTED]:  
> > > Failed to execute [org.elasticsearch.action.search.SearchRequest@1599f755]  
> > > org.elasticsearch.search.query.QueryPhaseExecutionException:  
> > > [haw\_index][2]: ..... .....: Query Failed [Failed to  
> > > execute main query]  
> > > at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:198)  
> > > at  
> > > org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:234)  
> > > at  
> > > org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:140)  
> > > at  
> > > org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:80)  
> > > at  
> > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:204)  
> > > at  
> > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:191)  
> > > at  
> > > org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:177)  
> > > at  
> > > java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
> > > at  
> > > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
> > > at java.lang.Thread.run(Thread.java:619)  
> > > Caused by: [Error: internal error: 113]  
> > > [Near : {... doc['age'].value\>param3 ? pow( ....}]  
> > > ^  
> > > [Line: 1, Column: 1]  
> > > at  
> > > org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:439)  
> > > at  
> > > org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:142)  
> > > at  
> > > org.elasticsearch.common.mvel2.optimizers.dynamic.DynamicOptimizer.optimizeAccessor(DynamicOptimizer.java:67)  
> > > at org.elasticsearch.common.mvel2.ast.ASTNode.optimize(ASTNode.java:157)  
> > > at  
> > > org.elasticsearch.common.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:113)  
> > > at  
> > > org.elasticsearch.common.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:116)  
> > > at  
> > > org.elasticsearch.common.mvel2.MVELRuntime.execute(MVELRuntime.java:85)  
> > > at  
> > > org.elasticsearch.common.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:123)  
> > > at  
> > > org.elasticsearch.common.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:116)  
> > > at  
> > > org.elasticsearch.script.mvel.MvelScriptEngineService$MvelSearchScript.run(MvelScriptEngineService.java:192)  
> > > at  
> > > org.elasticsearch.script.mvel.MvelScriptEngineService$MvelSearchScript.runAsFloat(MvelScriptEngineService.java:197)  
> > > at  
> > > org.elasticsearch.index.query.CustomScoreQueryParser$ScriptScoreFunction.factor(CustomScoreQueryParser.java:129)  
> > > at  
> > > org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery$CustomBoostFactorScorer.score(FiltersFunctionScoreQuery.java:314)  
> > > at  
> > > org.apache.lucene.search.TopScoreDocCollector$InOrderTopScoreDocCollector.collect(TopScoreDocCollector.java:47)  
> > > at org.apache.lucene.search.Scorer.score(Scorer.java:90)  
> > > at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:581)  
> > > at  
> > > org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:195)  
> > > at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:445)  
> > > at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:426)  
> > > at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:342)  
> > > at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:330)  
> > > at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:194)  
> > > ... 9 more  
> > > Caused by: java.lang.RuntimeException: internal error: 113  
> > > at  
> > > org.elasticsearch.common.mvel2.math.MathProcessor.toType(MathProcessor.java:139)  
> > > at  
> > > org.elasticsearch.common.mvel2.math.MathProcessor.doPrimWrapperArithmetic(MathProcessor.java:90)  
> > > at  
> > > org.elasticsearch.common.mvel2.math.MathProcessor.\_doOperations(MathProcessor.java:214)  
> > > at  
> > > org.elasticsearch.common.mvel2.math.MathProcessor.doOperations(MathProcessor.java:78)  
> > > at  
> > > org.elasticsearch.common.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:116)  
> > > at  
> > > org.elasticsearch.common.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:38)  
> > > at  
> > > org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:959)  
> > > at  
> > > org.elasticsearch.common.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:343)  
> > > ... 30 more

--

---

<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, 3:01am UTC](https://discuss.elastic.co/t/mvel-and-data-types/9905/5 "2017-07-06T03:01:55Z")

</div>


