MVEL scripting to return 0 or 1 for a boolean

Is there a function, or a way to include a boolean in my script like this

(doc['field1'].value == doc['field2'].value) and that in the parentheses
returns a numeric value 0 or 1 ?

I want to add this to functions and multiply by score in my function here.
This seems easier than making a filter based on that conditional.

"functions": [
{
"script_score": {
"script": "log(_score * (doc['field1'].value ==
doc['field2'].value)"
}
}
]

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/22c88d38-b1cd-4228-96bb-58838463c2bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

On 19 April 2014 20:57, Shane Neeley sneeley@molecularmatch.com wrote:

"script": "log(_score * (doc['field1'].value == doc['field2'].value)"

"script": "log(_score * ((doc['field1'].value == doc['field2'].value) ? :
1 : 0)"

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAPt3XKQMsgaOB4gQOddeUt%2BX%2BVBFEcaOX00397mc3v62-nfsxA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Thanks Clinton. Can you help me through this error?

Here is a couple of documents that return on a regular script score.
"hits": {
"total": 246,
"max_score": 1.293869,
"hits": [
{
"_index": "intent",
"_type": "intent",
"_score": 1.293869,
"_source": {
"alias": "RAS",
"rootTerm": "RAS"
}
},
{
"_index": "intent",
"_type": "intent",
"_score": 0.9466758,
"_source": {
"rootTerm": "3-Methyl-Aspartic Acid",
"alias": "3MA"
}
...]

Then when I add script score, only the first hit should still have a score:
"script_score": {
"script": "log(_score * ((doc['alias'].value ==
doc['rootTerm'].value) ? : 1 : 0))"
}

But I get this error..

{
"error": "SearchPhaseExecutionException[Failed to execute phase [query],
all shards failed; shardFailures {[Cq92Pqk5QYayO_4af76HjA][intent][0]:
QueryPhaseExecutionException[[intent][0]: query[function score (term:ras~2,
functions: [{filter(:), function [script[log(_score *
((doc['alias'].value == doc['rootTerm'].value) ? : 1 : 0))], params
[null]]}])],from[0],size[10]: Query Failed [Failed to execute main query]];
nested: CompileException[[Error: illegal use of operator:
TERNARY_ELSE]\n[Near : {... ((doc['alias'].value == doc['rootTerm'].value)
? : 1 : 0)) ....}]\n
^\n[Line: 1, Column: 63]]; }{[Cq92Pqk5QYayO_4af76HjA][intent][1]:
QueryPhaseExecutionException[[intent][1]: query[function score (term:ras~2,
functions: [{filter(:), function [script[log(_score *
((doc['alias'].value == doc['rootTerm'].value) ? : 1 : 0))], params
[null]]}])],from[0],size[10]: Query Failed [Failed to execute main query]];
nested: CompileException[[Error: illegal use of operator:
TERNARY_ELSE]\n[Near : {... ((doc['alias'].value == doc['rootTerm'].value)
? : 1 : 0)) ....}]\n
^\n[Line: 1, Column: 63]]; }{[Cq92Pqk5QYayO_4af76HjA][intent][2]:
QueryPhaseExecutionException[[intent][2]: query[function score (term:ras~2,
functions: [{filter(:), function [script[log(_score *
((doc['alias'].value == doc['rootTerm'].value) ? : 1 : 0))], params
[null]]}])],from[0],size[10]: Query Failed [Failed to execute main query]];
nested: CompileException[[Error: illegal use of operator:
TERNARY_ELSE]\n[Near : {... ((doc['alias'].value == doc['rootTerm'].value)
? : 1 : 0)) ....}]\n
^\n[Line: 1, Column: 63]]; }{[Cq92Pqk5QYayO_4af76HjA][intent][3]:
QueryPhaseExecutionException[[intent][3]: query[function score (term:ras~2,
functions: [{filter(:), function [script[log(_score *
((doc['alias'].value == doc['rootTerm'].value) ? : 1 : 0))], params
[null]]}])],from[0],size[10]: Query Failed [Failed to execute main query]];
nested: CompileException[[Error: illegal use of operator:
TERNARY_ELSE]\n[Near : {... ((doc['alias'].value == doc['rootTerm'].value)
? : 1 : 0)) ....}]\n
^\n[Line: 1, Column: 63]]; }{[Cq92Pqk5QYayO_4af76HjA][intent][4]:
QueryPhaseExecutionException[[intent][4]: query[function score (term:ras~2,
functions: [{filter(:), function [script[log(_score *
((doc['alias'].value == doc['rootTerm'].value) ? : 1 : 0))], params
[null]]}])],from[0],size[10]: Query Failed [Failed to execute main query]];
nested: CompileException[[Error: illegal use of operator:
TERNARY_ELSE]\n[Near : {... ((doc['alias'].value == doc['rootTerm'].value)
? : 1 : 0)) ....}]\n
^\n[Line: 1, Column: 63]]; }]",
"status": 500
}

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/06ace2ef-0759-478a-99ab-a5232493efba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Probably just remove the colon after the question mark (typo?):

((doc['alias'].value == doc['rootTerm'].value) ? 1 : 0))

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/ecc3abb6-8663-4c10-8831-713ea38b4263%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Probably just remove the colon after the question mark (typo?):

((doc['alias'].value == doc['rootTerm'].value) ? 1 : 0)

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/bc45f154-a0b3-4847-83e2-3acb404a73d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thanks Binh you were right

On Monday, April 21, 2014 4:53:43 PM UTC-5, Binh Ly wrote:

Probably just remove the colon after the question mark (typo?):

((doc['alias'].value == doc['rootTerm'].value) ? 1 : 0)

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/8b269bb4-c54f-4cbf-8c91-3d32bbe3a483%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.