_type field

Deprecated in 6.0.0.

See Removal of mapping types

Each document indexed is associated with a _type 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:

  1. # Example documents
  2. PUT my-index-000001/_doc/1?refresh=true
  3. {
  4. "text": "Document with type 'doc'"
  5. }
  6. GET my-index-000001/_search
  7. {
  8. "query": {
  9. "term": {
  10. "_type": "_doc"
  11. }
  12. },
  13. "aggs": {
  14. "types": {
  15. "terms": {
  16. "field": "_type",
  17. "size": 10
  18. }
  19. }
  20. },
  21. "sort": [
  22. {
  23. "_type": {
  24. "order": "desc"
  25. }
  26. }
  27. ],
  28. "script_fields": {
  29. "type": {
  30. "script": {
  31. "lang": "painless",
  32. "source": "doc['_type']"
  33. }
  34. }
  35. }
  36. }

Querying on the _type field

Aggregating on the _type field

Sorting on the _type field

Accessing the _type field in scripts