🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# _type field 每个索引的文档都与一个 **[_type](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/mapping-type-field.html)**(请参阅 “**[Mapping Types](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/mapping.html#mapping-type)[edit](https://github.com/elastic/elasticsearch/edit/5.3/docs/reference/mapping.asciidoc)**” 一节)以及一个 **[_id](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/mapping-id-field.html) **相关联。 为了使类型名称快速搜索,**[_type](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/mapping-type-field.html) **字段被索引。 该** _type **字段的值可以在查询,聚合,脚本以及排序时访问: | `# Example documents` `curl -XPUT ``'localhost:9200/my_index/type_1/1?pretty'` `-H ``'Content-Type: application/json'` `-d'` `{` `"text"``: ``"Document with type 1"` `}` `'` `curl -XPUT ``'localhost:9200/my_index/type_2/2?refresh=true&pretty'` `-H ``'Content-Type: application/json'` `-d'` `{` `"text"``: ``"Document with type 2"` `}` `'` `curl -XGET ``'localhost:9200/my_index/_search?pretty'` `-H ``'Content-Type: application/json'` `-d'` `{` `"query"``: {` `"terms"``: {` `"_type"``: [ ``"type_1"``, ``"type_2"` `] ``# 1` `}` `},` `"aggs"``: {` `"types"``: {` `"terms"``: {` `"field"``: ``"_type"``, ``# 2` `"size"``: 10` `}` `}` `},` `"sort"``: [` `{` `"_type"``: { ``# 3` `"order"``: ``"desc"` `}` `}` `],` `"script_fields"``: {` `"type"``: {` `"script"``: {` `"lang"``: ``"painless"``,` `"inline"``: ``"doc['_type']"` `# 4` `}` `}` `}` `}` `'` | | 1 | 在 **_type **字段上查询 | | 2 | 在 **_type **字段上聚合 | | 3 | 在 **_type **字段上排序 | | 4 | 在脚本中访问 **_type **字段 |