Using function_score error

Hello everyone

Do not understand why it does not work

Create some docs

PUT /searchtube/video/1
{
"title": "Sick Sad World: Cold Breeze on the Interstate",
"description": "Is your toll collector wearing pants, a skirt, or nothing
but a smile? Cold Breeze on the Interstate, next on Sick, Sad World.",
"views": 500,
"likes":2,
"created_at": "2014-04-22T08:00:00"
}

PUT /searchtube/video/2
{
"title": "Sick Sad World: The Severed Pianist",
"description": "When he turned up his nose at accordion lessons, they cut
off his inheritance molto allegro. The Severed Pianist, next on Sick, Sad
World.",
"views": 6000,
"likes": 100,
"created_at": "2014-04-22T12:00:00"
}

#SEARCH FUCNTION_SCORE
GET /searchtube/_search
{
"query": {
"function_score": {
"query": {"match": {"_all": "severed"}},
"script_score": {
"script": "_score * log(doc['likes'].value + doc['views'].value +
1)"
}
}
}
}

Error Response

{
"error": "SearchPhaseExecutionException[Failed to execute phase [query],
all shards failed; shardFailures {[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][0]:
SearchParseException[[searchtube][0]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][1]:
SearchParseException[[searchtube][1]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][2]:
SearchParseException[[searchtube][2]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][3]:
SearchParseException[[searchtube][3]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][4]:
SearchParseException[[searchtube][4]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}]",
"status": 400
}

What is this doing wrong? It is an example that I found
in https://www.found.no/foundation/function-scoring/

--
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/93f73abd-61b1-4569-bc2a-10b526e08b81%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mvel has been removed in recent versions of Elasticsearch due to security
issues. Either change your script to use Groovy (preferred) or install the
mvel plugin.

Cheers,

Ivan
On Oct 29, 2014 2:44 PM, "Manuel Sciuto" msciuto@viajeros.com wrote:

Hello everyone

Do not understand why it does not work

Create some docs

PUT /searchtube/video/1
{
"title": "Sick Sad World: Cold Breeze on the Interstate",
"description": "Is your toll collector wearing pants, a skirt, or
nothing but a smile? Cold Breeze on the Interstate, next on Sick, Sad
World.",
"views": 500,
"likes":2,
"created_at": "2014-04-22T08:00:00"
}

PUT /searchtube/video/2
{
"title": "Sick Sad World: The Severed Pianist",
"description": "When he turned up his nose at accordion lessons, they
cut off his inheritance molto allegro. The Severed Pianist, next on Sick,
Sad World.",
"views": 6000,
"likes": 100,
"created_at": "2014-04-22T12:00:00"
}

search FUCNTION_SCORE
GET /searchtube/_search
{
"query": {
"function_score": {
"query": {"match": {"_all": "severed"}},
"script_score": {
"script": "_score * log(doc['likes'].value + doc['views'].value +
1)"
}
}
}
}

Error Response

{
"error": "SearchPhaseExecutionException[Failed to execute phase
[query], all shards failed; shardFailures
{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][0]:
SearchParseException[[searchtube][0]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][1]:
SearchParseException[[searchtube][1]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][2]:
SearchParseException[[searchtube][2]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][3]:
SearchParseException[[searchtube][3]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][4]:
SearchParseException[[searchtube][4]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}]",
"status": 400
}

What is this doing wrong? It is an example that I found in
A Gentle Intro to Function Scoring | Elastic Blog

--
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/93f73abd-61b1-4569-bc2a-10b526e08b81%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/93f73abd-61b1-4569-bc2a-10b526e08b81%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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/CALY%3DcQB8KNZrKqPhAhUqzTL0GOKbaNO6fNjvZHDdMa08CV%2Bdfg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

The root cause of the error is here:
"ScriptException[dynamic scripting for [mvel] disabled]; "

I would guess you are running on ES 1.2 or 1.3? Dynamic scripting was
disabled by default in 1.2, and for non sandboxed languages in 1.3. In
1.4, the default script language was changed to Groovy, which is sandboxed,
and thus can be safely compiled dynamically.

See this blog for more details:

If running in 1.3, you can simply change the language of the script:
GET /searchtube/_search
{
"query": {
"function_score": {
"query": {"match": {"_all": "severed"}},
"script_score": {
"script": "_score * log(doc['likes'].value + doc['views'].value + 1)"
,
"lang": "groovy"
}
}
}
}

Although you could also use the "expr" lang (expressions) for this simple
script, which will be much faster!

On Wednesday, October 29, 2014 11:44:07 AM UTC-7, Manuel Sciuto wrote:

Hello everyone

Do not understand why it does not work

Create some docs

PUT /searchtube/video/1
{
"title": "Sick Sad World: Cold Breeze on the Interstate",
"description": "Is your toll collector wearing pants, a skirt, or
nothing but a smile? Cold Breeze on the Interstate, next on Sick, Sad
World.",
"views": 500,
"likes":2,
"created_at": "2014-04-22T08:00:00"
}

PUT /searchtube/video/2
{
"title": "Sick Sad World: The Severed Pianist",
"description": "When he turned up his nose at accordion lessons, they
cut off his inheritance molto allegro. The Severed Pianist, next on Sick,
Sad World.",
"views": 6000,
"likes": 100,
"created_at": "2014-04-22T12:00:00"
}

search FUCNTION_SCORE
GET /searchtube/_search
{
"query": {
"function_score": {
"query": {"match": {"_all": "severed"}},
"script_score": {
"script": "_score * log(doc['likes'].value + doc['views'].value +
1)"
}
}
}
}

Error Response

{
"error": "SearchPhaseExecutionException[Failed to execute phase
[query], all shards failed; shardFailures
{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][0]:
SearchParseException[[searchtube][0]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][1]:
SearchParseException[[searchtube][1]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][2]:
SearchParseException[[searchtube][2]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][3]:
SearchParseException[[searchtube][3]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][4]:
SearchParseException[[searchtube][4]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}]",
"status": 400
}

What is this doing wrong? It is an example that I found in
A Gentle Intro to Function Scoring | Elastic Blog

--
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/7899a825-47d8-496d-9c4d-e0fcc26797b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thank you very much !!!

How do you recommend that I do my script_score?

El sábado, 1 de noviembre de 2014 13:02:13 UTC-3, Ryan Ernst escribió:

The root cause of the error is here:
"ScriptException[dynamic scripting for [mvel] disabled]; "

I would guess you are running on ES 1.2 or 1.3? Dynamic scripting was
disabled by default in 1.2, and for non sandboxed languages in 1.3. In
1.4, the default script language was changed to Groovy, which is sandboxed,
and thus can be safely compiled dynamically.

See this blog for more details:
Elasticsearch Platform — Find real-time answers at scale | Elastic

If running in 1.3, you can simply change the language of the script:
GET /searchtube/_search
{
"query": {
"function_score": {
"query": {"match": {"_all": "severed"}},
"script_score": {
"script": "_score * log(doc['likes'].value + doc['views'].value +
1)",
"lang": "groovy"
}
}
}
}

Although you could also use the "expr" lang (expressions) for this simple
script, which will be much faster!

On Wednesday, October 29, 2014 11:44:07 AM UTC-7, Manuel Sciuto wrote:

Hello everyone

Do not understand why it does not work

Create some docs

PUT /searchtube/video/1
{
"title": "Sick Sad World: Cold Breeze on the Interstate",
"description": "Is your toll collector wearing pants, a skirt, or
nothing but a smile? Cold Breeze on the Interstate, next on Sick, Sad
World.",
"views": 500,
"likes":2,
"created_at": "2014-04-22T08:00:00"
}

PUT /searchtube/video/2
{
"title": "Sick Sad World: The Severed Pianist",
"description": "When he turned up his nose at accordion lessons, they
cut off his inheritance molto allegro. The Severed Pianist, next on Sick,
Sad World.",
"views": 6000,
"likes": 100,
"created_at": "2014-04-22T12:00:00"
}

search FUCNTION_SCORE
GET /searchtube/_search
{
"query": {
"function_score": {
"query": {"match": {"_all": "severed"}},
"script_score": {
"script": "_score * log(doc['likes'].value + doc['views'].value +
1)"
}
}
}
}

Error Response

{
"error": "SearchPhaseExecutionException[Failed to execute phase
[query], all shards failed; shardFailures
{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][0]:
SearchParseException[[searchtube][0]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][1]:
SearchParseException[[searchtube][1]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][2]:
SearchParseException[[searchtube][2]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][3]:
SearchParseException[[searchtube][3]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][4]:
SearchParseException[[searchtube][4]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}]",
"status": 400
}

What is this doing wrong? It is an example that I found in
A Gentle Intro to Function Scoring | Elastic Blog

--
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/cba0a627-ebfb-4895-924f-84d1be7f81ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

I have an error

My mapping

  • "mappings": {
    • "comida": {
      • "dynamic": "true",
      • "numeric_detection": true,
      • "properties": {
        • "id": {
          • "type": "integer"
            },
        • "reviews": {
          • "type": "integer"
            },
        • "name": {
          • "analyzer": "myAnalyzerDestinos",
          • "type": "string"
            }
            }
            },
    • "actividades": {
      • "dynamic": "true",
      • "numeric_detection": true,
      • "properties": {
        • "id": {
          • "type": "integer"
            },
        • "reviews": {
          • "type": "integer"
            },
        • "name": {
          • "analyzer": "myAnalyzerDestinos",
          • "type": "string"
            }
            }
            },
    • "alojamiento": {
      • "dynamic": "true",
      • "numeric_detection": true,
      • "properties": {
        • "id": {
          • "type": "integer"
            },
        • "reviews": {
          • "type": "integer"
            },
        • "name": {
          • "analyzer": "myAnalyzerDestinos",
          • "type": "string"
            }
            }
            },
    • "transporte_&_servicios": {
      • "dynamic": "true",
      • "numeric_detection": true,
      • "properties": {
        • "id": {
          • "type": "integer"
            },
        • "reviews": {
          • "type": "integer"
            },
        • "name": {
          • "analyzer": "myAnalyzerDestinos",
          • "type": "string"
            }
            }
            }
            },

My Query

GET /business/_search
{
"query": {
"function_score": {
"query": {"match": {"name": "sheraton"}},
"script_score": {
"script": "_score doc['reviews'].value",
"lang": "groovy"
}
}
}
}

Response

{
"error": "SearchPhaseExecutionException[Failed to execute phase [query],
all shards failed; shardFailures {[pGQYzpifRMumKUcblgTp2Q][business][0]:
QueryPhaseExecutionException[[business][0]: query[function score (name:she
name:sher name:shera name:sherat name:sherato
name:sheraton,function=script[_score doc['reviews'].value], params
[null])],from[0],size[10]: Query Failed [Failed to execute main query]];
nested: GroovyScriptExecutionException[MissingMethodException[No signature
of method:
org.elasticsearch.script.groovy.GroovyScriptEngineService$GroovyScript$UpdateableFloat.call()
is applicable for argument types: (java.lang.Long) values: [11]\nPossible
solutions: wait(long), wait(), abs(), any(), wait(long, int),
and(java.lang.Number)]]; }{[pGQYzpifRMumKUcblgTp2Q][business][1]:
QueryPhaseExecutionException[[business][1]: query[function score (name:she
name:sher name:shera name:sherat name:sherato
name:sheraton,function=script[_score doc['reviews'].value], params
[null])],from[0],size[10]: Query Failed [Failed to execute main query]];
nested: GroovyScriptExecutionException[MissingMethodException[No signature
of method:
org.elasticsearch.script.groovy.GroovyScriptEngineService$GroovyScript$UpdateableFloat.call()
is applicable for argument types: (java.lang.Long) values: [16]\nPossible
solutions: wait(long), wait(), abs(), any(), wait(long, int),
and(java.lang.Number)]]; }]",
"status": 500
}

Why?

El sábado, 1 de noviembre de 2014 13:02:13 UTC-3, Ryan Ernst escribió:

The root cause of the error is here:
"ScriptException[dynamic scripting for [mvel] disabled]; "

I would guess you are running on ES 1.2 or 1.3? Dynamic scripting was
disabled by default in 1.2, and for non sandboxed languages in 1.3. In
1.4, the default script language was changed to Groovy, which is sandboxed,
and thus can be safely compiled dynamically.

See this blog for more details:
Elasticsearch Platform — Find real-time answers at scale | Elastic

If running in 1.3, you can simply change the language of the script:
GET /searchtube/_search
{
"query": {
"function_score": {
"query": {"match": {"_all": "severed"}},
"script_score": {
"script": "_score * log(doc['likes'].value + doc['views'].value +
1)",
"lang": "groovy"
}
}
}
}

Although you could also use the "expr" lang (expressions) for this simple
script, which will be much faster!

On Wednesday, October 29, 2014 11:44:07 AM UTC-7, Manuel Sciuto wrote:

Hello everyone

Do not understand why it does not work

Create some docs

PUT /searchtube/video/1
{
"title": "Sick Sad World: Cold Breeze on the Interstate",
"description": "Is your toll collector wearing pants, a skirt, or
nothing but a smile? Cold Breeze on the Interstate, next on Sick, Sad
World.",
"views": 500,
"likes":2,
"created_at": "2014-04-22T08:00:00"
}

PUT /searchtube/video/2
{
"title": "Sick Sad World: The Severed Pianist",
"description": "When he turned up his nose at accordion lessons, they
cut off his inheritance molto allegro. The Severed Pianist, next on Sick,
Sad World.",
"views": 6000,
"likes": 100,
"created_at": "2014-04-22T12:00:00"
}

search FUCNTION_SCORE
GET /searchtube/_search
{
"query": {
"function_score": {
"query": {"match": {"_all": "severed"}},
"script_score": {
"script": "_score * log(doc['likes'].value + doc['views'].value +
1)"
}
}
}
}

Error Response

{
"error": "SearchPhaseExecutionException[Failed to execute phase
[query], all shards failed; shardFailures
{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][0]:
SearchParseException[[searchtube][0]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][1]:
SearchParseException[[searchtube][1]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][2]:
SearchParseException[[searchtube][2]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][3]:
SearchParseException[[searchtube][3]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][4]:
SearchParseException[[searchtube][4]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}]",
"status": 400
}

What is this doing wrong? It is an example that I found in
A Gentle Intro to Function Scoring | Elastic Blog

--
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/d77e9d78-e7e7-4a9b-bb52-2cbf1c929aaf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

The error is in your groovy script, as indicated
by GroovyScriptExecutionException. All the other info is just making it
more difficult to help you.

"script": "_score doc['reviews'].value"

Your script doesn't use any operator. It's likely that you just want to
multiply: "_score * doc['reviews'].value".
In groovy, function call arguments do not need to be enclosed in brackets.
E.g. "println 'hello'" is equivalent to "println('hello')". By omitting the
operator, your script is trying to call _score (which is some
UpdatableFloat), with the document field as an argument.

Cheers!

Op maandag 3 november 2014 19:46:07 UTC+1 schreef Manuel Sciuto:

I have an error

My mapping

  • "mappings": {
    • "comida": {
      • "dynamic": "true",
      • "numeric_detection": true,
      • "properties": {
        • "id": {
          • "type": "integer"
            },
        • "reviews": {
          • "type": "integer"
            },
        • "name": {
          • "analyzer": "myAnalyzerDestinos",
          • "type": "string"
            }
            }
            },
    • "actividades": {
      • "dynamic": "true",
      • "numeric_detection": true,
      • "properties": {
        • "id": {
          • "type": "integer"
            },
        • "reviews": {
          • "type": "integer"
            },
        • "name": {
          • "analyzer": "myAnalyzerDestinos",
          • "type": "string"
            }
            }
            },
    • "alojamiento": {
      • "dynamic": "true",
      • "numeric_detection": true,
      • "properties": {
        • "id": {
          • "type": "integer"
            },
        • "reviews": {
          • "type": "integer"
            },
        • "name": {
          • "analyzer": "myAnalyzerDestinos",
          • "type": "string"
            }
            }
            },
    • "transporte_&_servicios": {
      • "dynamic": "true",
      • "numeric_detection": true,
      • "properties": {
        • "id": {
          • "type": "integer"
            },
        • "reviews": {
          • "type": "integer"
            },
        • "name": {
          • "analyzer": "myAnalyzerDestinos",
          • "type": "string"
            }
            }
            }
            },

My Query

GET /business/_search
{
"query": {
"function_score": {
"query": {"match": {"name": "sheraton"}},
"script_score": {
"script": "_score doc['reviews'].value",
"lang": "groovy"
}
}
}
}

Response

{
"error": "SearchPhaseExecutionException[Failed to execute phase
[query], all shards failed; shardFailures
{[pGQYzpifRMumKUcblgTp2Q][business][0]:
QueryPhaseExecutionException[[business][0]: query[function score (name:she
name:sher name:shera name:sherat name:sherato
name:sheraton,function=script[_score doc['reviews'].value], params
[null])],from[0],size[10]: Query Failed [Failed to execute main query]];
nested: GroovyScriptExecutionException[MissingMethodException[No signature
of method:
org.elasticsearch.script.groovy.GroovyScriptEngineService$GroovyScript$UpdateableFloat.call()
is applicable for argument types: (java.lang.Long) values: [11]\nPossible
solutions: wait(long), wait(), abs(), any(), wait(long, int),
and(java.lang.Number)]]; }{[pGQYzpifRMumKUcblgTp2Q][business][1]:
QueryPhaseExecutionException[[business][1]: query[function score (name:she
name:sher name:shera name:sherat name:sherato
name:sheraton,function=script[_score doc['reviews'].value], params
[null])],from[0],size[10]: Query Failed [Failed to execute main query]];
nested: GroovyScriptExecutionException[MissingMethodException[No signature
of method:
org.elasticsearch.script.groovy.GroovyScriptEngineService$GroovyScript$UpdateableFloat.call()
is applicable for argument types: (java.lang.Long) values: [16]\nPossible
solutions: wait(long), wait(), abs(), any(), wait(long, int),
and(java.lang.Number)]]; }]",
"status": 500
}

Why?

El sábado, 1 de noviembre de 2014 13:02:13 UTC-3, Ryan Ernst escribió:

The root cause of the error is here:
"ScriptException[dynamic scripting for [mvel] disabled]; "

I would guess you are running on ES 1.2 or 1.3? Dynamic scripting was
disabled by default in 1.2, and for non sandboxed languages in 1.3. In
1.4, the default script language was changed to Groovy, which is sandboxed,
and thus can be safely compiled dynamically.

See this blog for more details:
Elasticsearch Platform — Find real-time answers at scale | Elastic

If running in 1.3, you can simply change the language of the script:
GET /searchtube/_search
{
"query": {
"function_score": {
"query": {"match": {"_all": "severed"}},
"script_score": {
"script": "_score * log(doc['likes'].value + doc['views'].value +
1)",
"lang": "groovy"
}
}
}
}

Although you could also use the "expr" lang (expressions) for this simple
script, which will be much faster!

On Wednesday, October 29, 2014 11:44:07 AM UTC-7, Manuel Sciuto wrote:

Hello everyone

Do not understand why it does not work

Create some docs

PUT /searchtube/video/1
{
"title": "Sick Sad World: Cold Breeze on the Interstate",
"description": "Is your toll collector wearing pants, a skirt, or
nothing but a smile? Cold Breeze on the Interstate, next on Sick, Sad
World.",
"views": 500,
"likes":2,
"created_at": "2014-04-22T08:00:00"
}

PUT /searchtube/video/2
{
"title": "Sick Sad World: The Severed Pianist",
"description": "When he turned up his nose at accordion lessons, they
cut off his inheritance molto allegro. The Severed Pianist, next on Sick,
Sad World.",
"views": 6000,
"likes": 100,
"created_at": "2014-04-22T12:00:00"
}

search FUCNTION_SCORE
GET /searchtube/_search
{
"query": {
"function_score": {
"query": {"match": {"_all": "severed"}},
"script_score": {
"script": "_score * log(doc['likes'].value + doc['views'].value

  • 1)"
    }
    }
    }
    }

Error Response

{
"error": "SearchPhaseExecutionException[Failed to execute phase
[query], all shards failed; shardFailures
{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][0]:
SearchParseException[[searchtube][0]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][1]:
SearchParseException[[searchtube][1]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][2]:
SearchParseException[[searchtube][2]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][3]:
SearchParseException[[searchtube][3]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}{[vrJl1dg1RV2wqGZ2Hqv3zQ][searchtube][4]:
SearchParseException[[searchtube][4]: from[-1],size[-1]: Parse Failure
[Failed to parse source [{\n "query": {\n "function_score": {\n
"query": {"match": {"_all": "severed"}},\n "script_score":
{\n "script": "_score * log(doc['likes'].value +
doc['views'].value + 1)"\n }\n }\n }\n}\n]]]; nested:
QueryParsingException[[searchtube] script_score the script could not be
loaded]; nested: ScriptException[dynamic scripting for [mvel] disabled];
}]",
"status": 400
}

What is this doing wrong? It is an example that I found in
A Gentle Intro to Function Scoring | Elastic Blog

--
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/26cbb104-794c-4a5e-8397-18c015143ae8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.