【问题标题】:Elastic Search, field name starting with at signElastic Search,以at开头的字段名
【发布时间】:2016-12-13 16:48:35
【问题描述】:

我正在使用 elasticsearch 1.3.4 和 groovy。我想做的是在弹性搜索查询中使用脚本:

{
  "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"
      }
    }
  }
}

由于某种原因,字段名称以 at 符号开头。问题是 groovy 将 at 符号视为特殊字符(http://groovy.codehaus.org/Operators)。来自 groovy 的错误消息:

嵌套:GroovyScriptCompilationException[MultipleCompilationErrorsException[启动失败:\nScript78.groovy:1:无法解析类字段,无法找到注释类\n@

那么是否可以让以“@”符号开头的字段进行 groovy 工作?

【问题讨论】:

  • 你试过用 unicode 值替换“@”吗?例如doc['\u0040field1'].value
  • 有效!非常感谢!

标签: groovy elasticsearch


【解决方案1】:

将“@”替换为 unicode value 将阻止 Groovy 处理它

例如替换

doc['@field1'].value

doc['\u0040field1'].value

【讨论】:

    猜你喜欢
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多