Elastic search, field name starting with a
I am using elasticsearch 1.3.4 and groovy. What I am trying to do is use a script in an elastic search query:
{
"size": 0,
"query": {
"bool": {
"must": [
{
"range": {
"@timestamp": {
"gte": "2014-12-08T03:40:00.000Z",
"lte": "2014-12-08T03:40:59.999Z"
}
}
}
],
"must_not": []
}
},
"facets": {
"myFacet": {
"terms": {
"script": "doc['@field1'].value + ':' + doc['@field2'].value"
}
}
}
}
For some reason, the field name starts with at. The problem is that groovy treats the at sign as a special character ( http://groovy.codehaus.org/Operators ). Error messages from groovy:
nested: GroovyScriptCompilationException [MultipleCompilationErrorsException [autoload completed: \ nScript78.groovy: 1: cannot resolve class field, cannot find class for annotation \ n @
... Is it possible to make groovy work with a field that starts with the "@" sign?
+3
source to share
1 answer
Replacing "@" with unicode will prevent Groovy from handling it
eg. replace
doc['@field1'].value
from
doc['\u0040field1'].value
+1
source to share