Elasticsearch无法在具有嵌套字段的脚本中访问`doc`

时间:2016-10-28 14:50:21

标签: elasticsearch groovy elasticsearch-dsl

使用ES 2.3.3 我的文档映射的一部分如下:

"rents": {
  "type": "nested",
  "properties": {.........e.g. "avg"}
},
"location": {
    "type": "geo_point"
}

在剧本中,我试图找到这个领域的距离

 {
  "nested": {
    "path": "rents",
    "query": {
      "function_score": {
        "query": {...some rents queries....},
        "functions": [
          { 
            "script_score": {
              "params": {
                "center_lat": 23.509518,
                "center_long":-18.378842
              },
              "script": "return doc['location'].distanceInMiles(center_lat, center_long)*rents.avg;"
            }
          }
        ]
      }
    }
  }
}

但这会引发错误:

"reason": {
  "type": "script_exception",
  "reason": "failed to run inline script [return doc['location'].distanceInMiles(center_lat, center_long)*rents.avg;] using lang [groovy]",
  "caused_by": {
    "type": "null_pointer_exception",
    "reason": null
  }
}

我正在关注指南https://www.elastic.co/guide/en/elasticsearch/reference/2.3/modules-scripting.html#_document_fields然后我做错了什么?请注意我的所有文档都有location字段,其中没有一个为空或空。我的上述脚本似乎无法使用doc

请注意即使我从脚本中删除rents.avg错误仍然存​​在。所以我怀疑docpath: rents内是不可用的?如果是,那么如何让它发挥作用?

0 个答案:

没有答案