properties

Type mappings, object fields and nested fields contain sub-fields, called properties. These properties may be of any data type, including object and nested. Properties can be added:

  • explicitly by defining them when creating an index.
  • explicitly by defining them when adding or updating a mapping type with the PUT mapping API.
  • dynamically just by indexing documents containing new fields.

Below is an example of adding properties to a mapping type, an object field, and a nested field:

  1. PUT my-index-000001
  2. {
  3. "mappings": {
  4. "properties": {
  5. "manager": {
  6. "properties": {
  7. "age": { "type": "integer" },
  8. "name": { "type": "text" }
  9. }
  10. },
  11. "employees": {
  12. "type": "nested",
  13. "properties": {
  14. "age": { "type": "integer" },
  15. "name": { "type": "text" }
  16. }
  17. }
  18. }
  19. }
  20. }
  21. PUT my-index-000001/_doc/1
  22. {
  23. "region": "US",
  24. "manager": {
  25. "name": "Alice White",
  26. "age": 30
  27. },
  28. "employees": [
  29. {
  30. "name": "John Smith",
  31. "age": 34
  32. },
  33. {
  34. "name": "Peter Brown",
  35. "age": 26
  36. }
  37. ]
  38. }

Properties in the top-level mappings definition.

Properties under the manager object field.

Properties under the employees nested field.

An example document which corresponds to the above mapping.

The properties setting is allowed to have different settings for fields of the same name in the same index. New properties can be added to existing fields using the PUT mapping API.

Dot notation

Inner fields can be referred to in queries, aggregations, etc., using dot notation:

  1. GET my-index-000001/_search
  2. {
  3. "query": {
  4. "match": {
  5. "manager.name": "Alice White"
  6. }
  7. },
  8. "aggs": {
  9. "Employees": {
  10. "nested": {
  11. "path": "employees"
  12. },
  13. "aggs": {
  14. "Employee Ages": {
  15. "histogram": {
  16. "field": "employees.age",
  17. "interval": 5
  18. }
  19. }
  20. }
  21. }
  22. }
  23. }

The full path to the inner field must be specified.