![](/img/trans.png)
[英]Elasticsearch: Sort the Documents on the index value of the search string in a text field
[英]How to search for documents in an elasticsearch index having value as empty array for a field?
我需要在elasticseach索引中獲取文檔,該文檔的字段為空數組(可以嵌套)嗎?
按以下方式進行操作不起作用
{
"query": {
"filter": {
"script": {
"script": "doc['arrayField'].length > 0"
}
}
}
}
要么
{
"query": {
"bool": {
"must": { "match_all": {} },
"filter": { "term": { "arrayField": [] }}
}
}
}
似乎我必須使用過濾器功能以及一些腳本,但無法弄清楚該怎么做。
要獲取具有空數組的文檔,我們需要找到字段的長度,並查看其長度是否小於1。請使用下面的有效查詢。
"query": {
"bool" : {
"must" : {
"script" : {
"script" : {
"inline": "doc['arrayField'].length < 1",
"lang": "painless"
}
}
}
}
}
如果您發現任何問題,請告訴我。
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.