Elasticsearch在对象

时间:2018-04-03 00:47:55

标签: elasticsearch groovy elasticsearch-2.0 elasticsearch-query

我的部分映射如下(我仍在使用ES2.4):

"name": {
  "type": "string"
},
"misc": {
  "type": "object",
  "dynamic": "true",
  "properties": {}
}

假设我的存储空间中只有一个文档,如下所示

{
  "name": "foobar",
  "misc": {
    "201804": 1,
    "201805": 10,
    "201806": 2,
    "201807": 1,
    "201808": 9,
    "201809": 1,
    "201810": 8,
    "201811": 1,
    "201812": 11
  }
}

在我的搜索查询中,我有一个groovy脚本,我试图找到misc对象中的键的值

dynamic_key = ....my logical calculation to find key....
//assume the calculated value of dynamic_key is "201808"
kvalue = doc['misc'][dynamic_key].value //value of kvalue should be 9 as dynamic_key="201808"

我收到此错误type: "no_class_def_found_error", reason: "java/lang/Throwable",因此动态键值选择失败。如果我将此行kvalue = doc['misc'][dynamic_key].value更改为kvalue = doc['misc.201805].value,则会正确找到该值。

知道如何实现我想要的目标吗?

0 个答案:

没有答案