我有以下当前使用动态脚本的查询。从那以后,我发现我的主机不支持这个,因为它具有更广泛的安全隐患。我将如何重写此脚本以使其不使用动态脚本?
{
"size": 0,
"aggs": {
"filtered_cells": {
"filter": {
"geo_bounding_box": {
"loc": {
"top_left": "58.645976, -13.515625",
"bottom_right": "50.524473, 2.436523"
}
}
},
"aggs": {
"cells": {
"geohash_grid": {
"field": "loc",
"precision": 2
},
"aggs": {
"center_lat": {
"avg": {
"script": "doc['loc'].lat"
}
},
"center_lon": {
"avg": {
"script": "doc['loc'].lon"
}
}
}
}
}
}
},
"query": {
"match_all": {}
}
}
最佳答案
您可以 store your scripts on the file system并从您的查询/聚合中引用它们。
使用以下内容创建名为 config/scripts/lat.groovy
的文件
doc['loc'].lat
使用以下内容创建另一个名为 config/scripts/lon.groovy
的文件
doc['loc'].lon
然后将您的查询更改为:
{
"size": 0,
"aggs": {
"filtered_cells": {
"filter": {
"geo_bounding_box": {
"loc": {
"top_left": "58.645976, -13.515625",
"bottom_right": "50.524473, 2.436523"
}
}
},
"aggs": {
"cells": {
"geohash_grid": {
"field": "loc",
"precision": 2
},
"aggs": {
"center_lat": {
"avg": {
"script_file": "lat"
}
},
"center_lon": {
"avg": {
"script_file": "lon"
}
}
}
}
}
}
},
"query": {
"match_all": {}
}
}
关于elasticsearch - 不使用动态脚本查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30143408/