ES 7.10.2 Join 类型查询详解:Nested、Parent-Child、Terms、Children
在 ES 7.10.2 中,join 类型查询提供了以下几种方式:\n\n1. Nested 查询:使用 nested 查询可以在一个文档中查询嵌套的字段。\n 示例:\n json\n {\n "query": {\n "nested": {\n "path": "nested_field",\n "query": {\n "bool": {\n "must": [\n { "match": { "nested_field.name": "value" } }\n ]\n }\n }\n }\n }\n }\n \n\n2. Parent-Child 查询:使用 parent-child 关系查询可以查询父文档或子文档。\n 示例:\n json\n {\n "query": {\n "has_parent": {\n "parent_type": "parent_type",\n "query": {\n "match": { "field": "value" }\n }\n }\n }\n }\n \n\n3. Terms 查询:使用 terms 查询可以查询具有指定关联关系的文档。\n 示例:\n json\n {\n "query": {\n "terms": {\n "field": ["value1", "value2"],\n "index": "index_name",\n "path": "join_field"\n }\n }\n }\n \n\n4. Children 查询:使用 children 查询可以查询具有指定关联关系的子文档。\n 示例:\n json\n {\n "query": {\n "has_child": {\n "type": "child_type",\n "query": {\n "match": { "field": "value" }\n }\n }\n }\n }\n \n\n这些是 ES 7.10.2 中 join 类型查询的几种常见方式,您可以根据具体的需求选择适合的查询方式。
原文地址: http://www.cveoy.top/t/topic/pswb 著作权归作者所有。请勿转载和采集!