我有一個帶有嵌套檔案的彈性索引。我正在嘗試按 id 及其嵌套檔案檢索多個檔案。使用應該查詢來檢索檔案本身很簡單,但是在哪里以及如何在其中包含嵌套的檔案查詢呢?
布爾“應該”查詢:
GET myIndex/_search
{
"query": {
"bool": {
"should": [
{
"term": {
"id": "123"
}
},
{
"term": {
"id": "456"
}
},
{
"term": {
"id": "789"
}
}
]
}
}
}
查詢以檢索嵌套檔案:
"nested": {
"path": "myNestedDocs",
"query": {
"match_all": {}
}
無法將嵌套查詢添加到每個術語查詢,因為這會產生決議例外:“[term] malformed query, expected [END_OBJECT] but found [FIELD_NAME]”
此外,不可能將嵌套檔案查詢添加到與術語查詢相同的級別,因為這樣它將被視為另一個 OR 子句并簡單地從索引中檢索所有檔案。
有任何想法嗎?謝謝!
uj5u.com熱心網友回復:
根據我的理解,您想匹配id串列中的任何一個并檢索嵌套檔案。如果我的理解正確,那么您需要將查詢與must子句結合起來,如下所示:
{
"query": {
"bool": {
"must": [
{
"terms": {
"id": [
"123",
"456",
"789"
]
}
},
{
"nested": {
"path": "myNestedDocs",
"query": {
"match_all": {}
}
}
}
]
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/473330.html
