Closed stacey-gammon closed 7 years ago
The value_type
does not handle boolean. The parser is too lenient and accepts invalid values (values that are not recognized as valid types) without throwing an error. You can try with value_type=foo
and you'll have the same output. It's too late for 5.0.0 but we can remove this leniency in 5.x. I'll not remove the blocker label since others may want to comment as well.
I've discovered a couple additional issues with boolean fields. It appears that using a painless script field of doc['alive'].value == false
fails with
"caused_by": {
"type": "class_cast_exception",
"reason": "Cannot cast from: boolean to boolean",
"caused_by": {
"type": "wrong_method_type_exception",
"reason": "cannot convert MethodHandle(long,long)boolean to (Object,boolean)boolean"
}
Along the same vein, using a script query like the following does not return any results (it has to be 0 or 1 to work as expected).
"script" : {
"inline" : "(doc['alive'].value) == params.value",
"lang" : "painless",
"params" : {
"value" : false
}
},
@Stacey-Gammon this is a known issue reported by ... you. The fix should come in 5.1.0 as stated here: https://github.com/elastic/elasticsearch/issues/20949
@jimferenczi would be good to document value_type
as well.
Let's check whether we can get rid of it first? If I read the code correctly, this information is not propagated to painless but only used by aggregations.
Addressed by #22135.
@jpountz I saw this was closed so I did some testing to see if we could remove our workaround in Kibana and I found that the terms agg no longer accepts boolean scripts. If I use a simplified version of the query Stacey provided above, I get an error:
Request:
{
"aggs":{
"1":{
"terms": {
"script": {
"inline" : "return true;",
"lang": "painless"
},
"value_type": "boolean"
}
}
}
}
Response
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 4,
"failed": 1,
"failures": [
{
"shard": 4,
"index": "foo",
"node": "bAWZQ2m9SGutXsY_I_WLfg",
"reason": {
"type": "aggregation_execution_exception",
"reason": "Unsupported script value [true]"
}
}
]
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
},
"aggregations": {
"1": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
}
}
Is this an unintentional side effect of the PR that closed this?
Let me dig into that, the issue reported an issue with the fact that the boolean
value type was not supported, so I closed it since it was addressed, but it looks like there is something else that prevents terms aggs on boolean scripts.
OK, this is because aggregations expect that scripts return numbers as a representation for boolean values, like boolean fields do, so for instance that query works:
GET index/_search
{
"aggs":{
"1":{
"terms": {
"script": {
"inline" : "return 1;",
"lang": "painless"
},
"value_type": "boolean"
}
}
}
}
It should be fixable though.
I opened a PR https://github.com/elastic/elasticsearch/pull/22201
This is showing up as a 5.0 blocker for kibana in https://github.com/elastic/kibana/issues/8677
I am requesting a scripted, painless field aggregation with value_type boolean, but it is being returned as a string. value_type double works as expected.
Request:
Response:
fwiw, I am capturing the request in slow log and when I pass
"value_type": "boolean"
, that line is getting stripped out. When I pass"value_type: "double"
it's being preserved in the logged request. I admit I am not sure if ES is stripping value_type or Kibana is.