【发布时间】:2019-01-03 12:26:48
【问题描述】:
对此有很多问题和答案,但仍然没有得到满意的答案。 弹性搜索版本:6.5
索引映射
"_doc": {
"properties": {
"ssid": {
"type": "long"
},
"nested_field": {
"type": "nested"
}
}
}
}
搜索查询:
{
"query": {
"bool": {
"filter": {
"script": {
"script": "params._source.nested_field.size() > 1"
}
}
}
}
}
也试过下面的查询,但没有运气
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "nested_field",
"query": {
"bool": {
"filter": {
"script": {
"script": "params._source.nested_field.size() > 1"
}
}
}
}
}
}
]
}
}
}
错误
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"params._source.nested_field.size() > 1",
" ^---- HERE"
],
"script": "params._source.nested_field.size() > 1",
"lang": "painless"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "testing_index",
"node": "XXXXXXXXXXXXXXXXXXXXXXX",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"params._source.nested_field.size() > 1",
" ^---- HERE"
],
"script": "params._source.nested_field.size() > 1",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
}
}
]
},
"status": 500
}
params._source.nested_field 在 scripted_field 中使用时返回嵌套数组,但在验证查询中不起作用。关于使用无痛脚本的嵌套查询的文档不完整。
【问题讨论】:
-
在过滤上下文中,Painless 无权访问_source 文档:elastic.co/guide/en/elasticsearch/painless/6.5/…,主要是出于性能原因。
-
验证嵌套值的替代方法是什么?
-
你最终解决了这个问题吗?我也有同样的问题...
-
@Rob:不,我们最近升级到了最新版本 7.2,我还没有尝试过相同的脚本。会让您知道这是否适用于最新版本。我真的很惊讶世界上没有人对这些 elaticsearch 的问题感兴趣。
-
@Avi 现在我有一个类似的问题 - discuss.elastic.co/t/… 你的问题解决了吗?
标签: elasticsearch scripting nested elasticsearch-painless