ネストされたドキュメントの配列を含むドキュメントがあります。ドキュメントに指定されたすべてのネストされたドキュメントが含まれている場合、一致を返す必要があります。ここelasticsearchに複数のネストされたドキュメントが含まれている場合、ドキュメントと一致する
は、マッピングの関連する部分である:
"element": {
"dynamic": "false",
"properties": {
"tenantId": {
"type": "string",
"index": "not_analyzed"
},
"fqn": {
"type": "string",
"index": "not_analyzed"
},
"id": {
"type": "string",
"index": "not_analyzed"
},
"name": {
"type": "string",
"index": "not_analyzed"
},
"type": {
"type": "string",
"index": "not_analyzed"
},
"location": {
"type": "string",
"index": "not_analyzed"
},
"tags": {
"type": "nested",
"properties": {
"id": {
"type": "string",
"index": "not_analyzed"
},
"dataSourceId": {
"type": "long",
"index": "not_analyzed"
},
"name": {
"type": "string",
"index": "not_analyzed"
},
"value": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
目標は、要素は、検索以外の追加タグを含めることが許可されているが(タグのリストのすべてが含まれている要素を返すことができるようにすることです要件)。ここで
は、私がこれまで持っているものです。
{
"query": {
"bool": {
"filter": {
"nested": {
"path": "tags",
"query": {
"bool": {
"must": [
{
"bool": {
"must":{
"term": { "tags.name": "name1" },
"term": { "tags.value": "value1" }
}
}
},
{
"bool": {
"must":{
"term": { "tags.name": "name2" },
"term": { "tags.value": "value2" }
}
}
}
]
}
}
}
}
}
}
}
このアプローチの問題点は、(それが単一の値のために正常に動作します)、それは、複数のタグ値を0ヒットを返すことです。これは、照会で一致するためにタグに複数の名前と値が必要であることが要求されているためです。これは明らかに起こり得ません。誰もがタグのリストのすべてを含む要素をクエリする方法を知っていますか?
編集:これはelasticsearchを使用しています。5.0
これをやり直そうとしていますか? https://www.elastic.co/guide/en/elasticsearch/guide/master/_finding_multiple_exact_values.html – JamesKn
@JamesKn用語のクエリを調べましたが、これらの値が暗黙の「または」演算であると私は理解しています。私は "and"操作が必要です。 –