0
我有以下的文檔結構:ElasticSearch查詢嵌套對象
"IDNumberTypes": {
"ID": [
{
"@IDType": "Company Identification No.",
"IDValue": [
{
"#text": "CompanyID"
}
]
},
{
"@IDType": "Reg. Number",
"IDValue": [
{
"#text": "RegNumber"
}
]
},
{
"@IDType": "Tax ID Number",
"IDValue": [
{
"#text": "TaxNumber"
}
]
}
]
}
我想寫一個匹配TaxNumber但只有在「國稅號」的情況下查詢。 像這樣的東西在pseudoSQL:
IDNumberTypes.ID.IDValue.#text="TaxNumber" WHERE [email protected]="Tax ID Number"
只是做它像這樣明顯地導致返回包含一個對象,具有「@IDType」文件:「稅號」
"query": {
"bool": {
"must": {
"match": {
"IDNumberTypes.ID.IDValue.#text": {
"query": "TaxNumber",
"operator": "and"
}
}
},
"filter": {
"match": {
"[email protected]": {
"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"
}
}
}
}
}
}
}
}
}
}
}
可能請您提供更多的細節:其中ES版本,您使用的?什麼是你的ES文件的映射? –
我已經通過添加適當的映射對它進行了整理:請參閱OP – user2429408