Hi all
Using Elasticsearch 6.8.1 I'm seeing some very strange behavior with script_score
. Using either expression
or painless
lang, the script "42"
which should be a constant expression in either language that evaluates the same value for every document every time, is giving me two different results, even for the same document, when used to score a different query.
$ cat ~/audit.sh
#!/bin/bash
function search() {
curl -sS -X POST 'http://10.101.0.1:20400/saas/_search?pretty' -H content-type:application/json -d "$1"
}
search '{
"size": 1,
"_source": false,
"query": {
"function_score": {
"script_score": {
"script": {
"lang": "expression",
"source": "42"
}
},
"query": {
"bool": {
"filter": [
{
"exists": {
"field": "social_account.customer_codes"
}
}
]
}
}
}
}
}'
search '{
"size": 1,
"_source": false,
"query": {
"function_score": {
"script_score": {
"script": {
"lang": "expression",
"source": "42"
}
},
"query": {
"term": {
"_id" : "a903c3a5-32f5-45ba-b092-3a80dc4e965a"
}
}
}
}
}'
$ ~/audit.sh
{
"took" : 31,
"timed_out" : false,
"_shards" : {
"total" : 10,
"successful" : 10,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 441988,
"max_score" : 0.0,
"hits" : [
{
"_index" : "saas-data-2",
"_type" : "_doc",
"_id" : "a903c3a5-32f5-45ba-b092-3a80dc4e965a",
"_score" : 0.0
}
]
}
}
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 10,
"successful" : 10,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 42.0,
"hits" : [
{
"_index" : "saas-data-2",
"_type" : "_doc",
"_id" : "a903c3a5-32f5-45ba-b092-3a80dc4e965a",
"_score" : 42.0
}
]
}
}
I'm unsure why the score would be 42.0
in some cases and 0.0
in another, even on the same document.
Thanks in advance