Parent Id 查询
parent_id 查询用来寻找特定父文档下的子文档。假设有如下的字段映射:
PUT my_index{"mappings": {"_doc": {"properties": {"my_join_field": {"type": "join","relations": {"my_parent": "my_child"}}}}}}PUT my_index/_doc/1?refresh{"text": "This is a parent document","my_join_field": "my_parent"}PUT my_index/_doc/2?routing=1&refresh{"text": "This is a child document","my_join_field": {"name": "my_child","parent": "1"}}
GET /my_index/_search{"query": {"parent_id": {"type": "my_child","id": "1"}}}
参数
该查询需要两个必须的参数:
type:子文档类型,声明在 join 字段中的值;
—
id:父文档的 ID;
—
ignore_unmapped:设置为 true 时,它将忽略未映射的 type,并且将不匹配任何文档。当查询可能具有不同映射的多个索引时,此功能很有用。将其设置为 false(默认值),如果未映射 type,则查询将抛出异常。
