I would like to use a script to do the following:
{
"query": {
"match_all": {}
},
"facets": {
"user_facet": {
"terms": {
"field": "user_id",
"script": "term + \"_\" + _source.code"
}
}
}
}
This is similar to the answer given in this question: elastic search double facet
The only problem I have is my user_id and code fields are long types, rather than strings. Is there a way to make them strings so they can be combined with the script?
The particular error I am getting is this:
nested: ClassCastException[java.lang.String cannot be cast to java.lang.Number];
This might sound ridiculous, but I had the same issue, and the way I fixed it (for a VERY similar problems) was to drop the "field" specification so that it looks like this:
{
"query": {
"match_all": {}
},
"facets": {
"user_facet": {
"terms": {
"script": "term + \"_\" + _source.code"
}
}
}
}
I think it was trying to convert the output of the "script" execution back into the type of the field, causing the class cast exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With