[英]Elastic Search query for an AND condition on two properties of a nested object
我有如下所示的post_filter,在這里我試圖過濾學校名稱為HILL SCHOOL 並且包含名稱為JOY AND A的嵌套子對象的記錄。
上級對象存在於父對象中,該對象持有子對象的嵌套對象列表。
以上所有都是AND條件。
但是查詢似乎不起作用。 知道為什么嗎? 有沒有辦法組合兩個嵌套查詢?
GET /test_school/_search
{
"query": {
"match_all": {}
},
"post_filter": {
"bool": {
"must_not": [
{
"bool": {
"must": [
{
"term": {
"schoolname": {
"value": "HILL SCHOOL"
}
}
},
{
"nested": {
"path": "children",
"query": {
"bool": {
"must": [
{
"match": {
"name": "JACK"
}
}
]
}
}
}
},
{
"term": {
"children.section": {
"value": "A"
}
}
}
]
}
}
]
}
}
}
架構如下:
PUT /test_school
{
"mappings": {
"_doc": {
"properties": {
"schoolname": {
"type": "keyword"
},
"children": {
"type": "nested",
"properties": {
"name": {
"type": "keyword",
"index": true
},
"section": {
"type": "keyword",
"index": true
}
}
}
}
}
}
}
示例數據如下:
POST /test_school/_doc
{
"schoolname":"HILL SCHOOL",
"children":{
"name":"JOY",
"section":"A"
}
}
第二條記錄
POST /test_school/_doc
{
"schoolname":"HILL SCHOOL",
"children":{
"name":"JACK",
"section":"B"
}
}
https://stackoverflow.com/a/17543151/183217建議使用特殊的映射來處理嵌套對象。 您似乎對“跨對象匹配”問題犯規。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.