_type fieldedit

Each document indexed is associated with a _type (see the section called “Mapping Typesedit”) and an _id. The _type field is indexed in order to make searching by type name fast.

The value of the _type field is accessible in queries, aggregations, scripts, and when sorting:

# Example documents
PUT my_index/type_1/1
{
  "text": "Document with type 1"
}

PUT my_index/type_2/2
{
  "text": "Document with type 2"
}

GET my_index/type_*/_search
{
  "query": {
    "terms": {
      "_type": [ "type_1", "type_2" ] 
    }
  },
  "aggs": {
    "types": {
      "terms": {
        "field": "_type", 
        "size": 10
      }
    }
  },
  "sort": [
    {
      "_type": { 
        "order": "desc"
      }
    }
  ],
  "script_fields": {
    "type": {
      "script": {
        "lang": "painless",
        "inline": "doc['_type']" 
      }
    }
  }
}

Querying on the _type field

Aggregating on the _type field

Sorting on the _type field

Accessing the _type field in scripts