bool queryを使用してクエリを組み合わせることができます。
だから、あなたは、この例に似た、あなたのマッピングとデータを作成したと仮定すると:
PUT /blog
{
"mappings": {
"blog": {},
"post": {
"_parent": {
"type": "blog"
}
},
"comment": {
"_parent": {
"type": "post"
}
}
}
}
POST /blog/blog/_bulk
{ "index": { "_id": "21" }}
{ "name": "blog 11"}
{ "index": { "_id": "25" }}
{ "name": "blog 25" }
{ "index": { "_id": "22" }}
{ "name": "blog 24"}
POST /blog/post/_bulk
{ "index": { "_id": "1", "parent": "21" }}
{ "name": "post of blog 21 (with comments)"}
{ "index": { "_id": "2", "parent": "25" }}
{ "name": "post of blog 25 (with comments)"}
{ "index": { "_id": "3", "parent": "25" }}
{ "name": "post of blog 25 (without comments)"}
POST /blog/comment/_bulk
{ "index": { "_id": "10", "parent": "1", "routing": "21"}}
{ "name": "comment for post 1"}
{ "index": { "_id": "11", "parent": "2", "routing": "25" }}
{ "name": "comment for post 2"}
あなたのクエリは次のとおりです。
GET blog/post/_search
{
"query": {
"bool": {
"must": [
{
"parent_id": {
"type": "post",
"id": "25"
}
},
{
"has_child": {
"type": "comment",
"query": {
"match_all": {
}
}
}
}
]
}
}
}
多分でnested
タイプとしてあなたのコメントを保存するために、より適しているであろう投稿。
nested
とparent/child
の関係hereの相違点の詳細を読むことができます。