我正在使用 ElasticSearch 版本 7.17 使用它擁有的搜索 API 進行查詢。我在 ElasticSearch 中的索引中的資料是使用 Logstash 從 SQL 資料庫加載的。在查詢中,我使用must_not exists查詢來獲取類中的組中沒有 email_list 的檔案。我的映射和資料是這樣的,
{
"class": {
"properties": {
"id": {
"type": "long"
},
...
"status": {
"type": "long"
},
"group": {
"type": "nested",
"properties": {
"id": {
"type": "long"
},
"email_list": {
"type": "keyword"
},
...
}
}
}
}
}
{
"class": {
"id": "15",
...
"status": 1,
"group": {
"id": 100,
...
"email_list": [
"[email protected]",
"[email protected]",
"[email protected]"
]
},
}
}
到目前為止,我已經嘗試了幾個查詢,包括嵌套查詢,這些是我嘗試過的一些查詢,
{
"query": {
"bool": {
"must_not": [
{
"exists": {
"field": "class.group.email_list"
}
}
]
}
}
}
{
"query": {
"bool": {
"must_not": [
{
"nested": {
"path": "class.group",
"query": {
"exists": {
"field": "email_list"
}
}
}
}
]
}
}
}
但是,這些查詢總是回傳包含 email_list 的檔案。難道我做錯了什么?任何幫助都會很棒
謝謝
uj5u.com熱心網友回復:
您需要class.group.email_list在嵌套查詢中使用完整的欄位名稱。下面的查詢會給你預期的結果。
{
"query": {
"bool": {
"must_not": [
{
"nested": {
"path": "class.group",
"query": {
"exists": {
"field": "class.group.email_list"
}
}
}
}
]
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/513904.html
標籤:弹性搜索木花弹性堆栈
