💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
# Parent Id Query parent_id 查询可以用来查找那些属于一个特殊父类型的子文档。给出如下映射的定义: | `curl -XPUT ``'localhost:9200/my_index?pretty'` `-d'` `{` `"mappings"``: {` `"blog_post"``: {` `"properties"``: {` `"name"``: {` `"type"``: ``"keyword"` `}` `}` `},` `"blog_tag"``: {` `"_parent"``: {` `"type"``: ``"blog_post"` `},` `"_routing"``: {` `"required"``: ``true` `}` `}` `}` `}'` | | `curl -XGET ``'localhost:9200/my_index/_search?pretty'` `-d'` `{` `"query"``: {` `"parent_id"` `: {` `"type"` `: ``"blog_tag"``,` `"id"` `: ``"1"` `}` `}` `}'` | 上面的设置与使用下面的 [`has_parent`](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-query.html "Has Parent Query")查询在功能上相似,但是如果不需要做连接的话,下面的操作会更好。 | `curl -XGET ``'localhost:9200/my_index/_search?pretty'` `-d'` `{` `"query"``: {` `"has_parent"``: {` `"parent_type"``: ``"blog_post"``,` `"query"``: {` `"term"``: {` `"_id"``: ``"1"` `}` `}` `}` `}` `}'` | ## Parameters(参数) 这个查询有两个必备的参数。 | | | | --- | --- | | type | 子类型。必须是一个_parent字段定义的类型 | | id | 选择文档必须参照要求的parent文档id | | ignore_unmapped | 当设置为true时,这个参数将忽略一个未被映射的类型,这个查询将不匹配任何文档。这个在可能产生不同的映射的多索引查询中起作用。当设置为flase(默认值),如果类型未被映射,则查询将报异常。 |