我有一个映射:
"ntol-2020-05" : {
"mappings" : {
{
"properties": {
"_createdAt": {
"type": "date"
},
"_logType": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"device": {
"properties": {
...
}
},
"resp": {
"type": "nested",
"properties": {
"data": {
"type": "nested",
"properties": {
...
}
}
}
}
}
}
}
}
}
我用三个条件进行过滤:
我正在尝试使用查询进行过滤:
{“query”:{“bool”:{“must”:[{“term”:{“_ logType”:{“value”:“crawler”}}}},{“range”:{“_ createdAt”:{“gte“:” 2020-05-23“,” lte“:” 2020-05-23“,” time_zone“:” + 07:00“}}},{” nested“:{” path“:” resp“,“query”:{“script”:{“script”:{“source”:“doc ['resp']。size()> 0”}}}}}}}},“从”:0,“尺寸“:10}
返回错误:
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:94)",
"org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:41)",
"doc['resp'].size() > 0",
" ^---- HERE"
],
"script": "doc['resp'].size() > 0",
"lang": "painless",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "No field found for [resp] in mapping with types []"
}
}
如果我使用脚本
"doc.containsKey('resp') && doc['resp'].size() > 0"
,它将返回hits length = 0。Help me. Thanks!
最佳答案
您可以使用exist返回“嵌套”字段“resp”具有值的文档。
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "resp",
"query": {
"bool": {
"filter": {
"exists": {
"field": "resp"
}
}
}
}
}
}
]
}
},
"from": 0,
"size": 10
}
关于elasticsearch - 如何在Elasticsearch 7.5中过滤嵌套对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62056365/