簡體   English   中英

對嵌套對象的ElasticSearch查詢

[英]ElasticSearch Query on nested object

我具有以下文檔結構:

           "IDNumberTypes": {
              "ID": [
                 {
                    "@IDType": "Company Identification No.",
                    "IDValue": [
                       {
                          "#text": "CompanyID"
                       }
                    ]
                 },
                 {
                    "@IDType": "Reg. Number",
                    "IDValue": [
                       {
                          "#text": "RegNumber"
                       }
                    ]
                 },
                 {
                    "@IDType": "Tax ID Number",
                    "IDValue": [
                       {
                          "#text": "TaxNumber"
                       }
                    ]
                 }
              ]
           }

我正在嘗試編寫一個與TaxNumber匹配的查詢,但僅在“國家稅號”的上下文中。 在偽SQL中是這樣的:

IDNumberTypes.ID.IDValue.#text="TaxNumber" WHERE IDNumberTypes.ID.@IDType="Tax ID Number"

這樣做顯然會導致返回包含“ @IDType”對象的文檔:“稅號”

"query": {
  "bool": {
     "must": {
        "match": {
           "IDNumberTypes.ID.IDValue.#text": {
              "query": "TaxNumber",
              "operator": "and"
           }
        }
     },
     "filter": {
        "match": {
           "IDNumberTypes.ID.@IDType": {
              "query": "Tax ID Number",
              "operator": "and"
           }
        }
     }
  }
}

...但不能確保我要查找的對象必須具有以下特定結構:

{
 "@IDType": "Tax ID Number",
 "IDValue": [{
              "#text": "TaxNumber"
             }]
}

如何正確過濾/構建查詢?

我已經通過添加適當的映射對其進行了整理:

{
   "mappings": {
     "doxx": {
       "properties": {
         "IDNumberTypes": {
           "properties": {
             "ID": {
               "type": "nested",
               "properties": {
                 "@IDType": {
                   "type": "string"
                 },
                 "IDValue": {
                   "type": "nested",
                   "properties": {
                     "#text": {
                       "type": "string"
                     },
                     "@IDnotes": {
                       "type": "string"
                     }
                   }
                 }
               }
             }
           }
         }
       }
     }
   }
 }

正確的映射:

{
   "mappings": {
     "doxx": {
       "properties": {
         "IDNumberTypes": {
           "properties": {
             "ID": {
               "type": "nested",
               "properties": {
                 "@IDType": {
                   "type": "string"
                 },
                 "IDValue": {
                   "type": "nested",
                   "properties": {
                     "#text": {
                       "type": "string"
                     },
                     "@IDnotes": {
                       "type": "string"
                     }
                   }
                 }
               }
             }
           }
         }
       }
     }
   }
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM