0

使用 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从脚本中删除错误仍然存​​在。所以我的怀疑是doc不是里面不可用path: rents?如果是这样,那么如何让它工作?

4

0 回答 0