[英]How to search for documents in an elasticsearch index having value as empty array for a field?
I need to get documents in an elasticseach index which have empty array for a field (which can be nested)? 我需要在elasticseach索引中获取文档,该文档的字段为空数组(可以嵌套)吗?
Doing it the below way is not working 按以下方式进行操作不起作用
{
"query": {
"filter": {
"script": {
"script": "doc['arrayField'].length > 0"
}
}
}
}
or 要么
{
"query": {
"bool": {
"must": { "match_all": {} },
"filter": { "term": { "arrayField": [] }}
}
}
}
It seems like I have to use the filter feature, alongwith some script but can't figure out how. 似乎我必须使用过滤器功能以及一些脚本,但无法弄清楚该怎么做。
To get documents with the empty array we find the length of the field and see if it's length is less than 1. Please, the working query below. 要获取具有空数组的文档,我们需要找到字段的长度,并查看其长度是否小于1。请使用下面的有效查询。
"query": {
"bool" : {
"must" : {
"script" : {
"script" : {
"inline": "doc['arrayField'].length < 1",
"lang": "painless"
}
}
}
}
}
Let me know if you find any issues. 如果您发现任何问题,请告诉我。
Thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.