properties.asciidoc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. [[properties]]
  2. === `properties`
  3. Type mappings, <<object,`object` fields>> and <<nested,`nested` fields>>
  4. contain sub-fields, called `properties`. These properties may be of any
  5. <<mapping-types,datatype>>, including `object` and `nested`. Properties can
  6. be added:
  7. * explicitly by defining them when <<indices-create-index,creating an index>>.
  8. * explicitly by defining them when adding or updating a mapping type with the <<indices-put-mapping,PUT mapping>> API.
  9. * <<dynamic-mapping,dynamically>> just by indexing documents containing new fields.
  10. Below is an example of adding `properties` to a mapping type, an `object`
  11. field, and a `nested` field:
  12. [source,console]
  13. --------------------------------------------------
  14. PUT my_index
  15. {
  16. "mappings": {
  17. "properties": { <1>
  18. "manager": {
  19. "properties": { <2>
  20. "age": { "type": "integer" },
  21. "name": { "type": "text" }
  22. }
  23. },
  24. "employees": {
  25. "type": "nested",
  26. "properties": { <3>
  27. "age": { "type": "integer" },
  28. "name": { "type": "text" }
  29. }
  30. }
  31. }
  32. }
  33. }
  34. PUT my_index/_doc/1 <4>
  35. {
  36. "region": "US",
  37. "manager": {
  38. "name": "Alice White",
  39. "age": 30
  40. },
  41. "employees": [
  42. {
  43. "name": "John Smith",
  44. "age": 34
  45. },
  46. {
  47. "name": "Peter Brown",
  48. "age": 26
  49. }
  50. ]
  51. }
  52. --------------------------------------------------
  53. <1> Properties in the top-level mappings definition.
  54. <2> Properties under the `manager` object field.
  55. <3> Properties under the `employees` nested field.
  56. <4> An example document which corresponds to the above mapping.
  57. TIP: The `properties` setting is allowed to have different settings for fields
  58. of the same name in the same index. New properties can be added to existing
  59. fields using the <<indices-put-mapping,PUT mapping API>>.
  60. ==== Dot notation
  61. Inner fields can be referred to in queries, aggregations, etc., using _dot
  62. notation_:
  63. [source,console]
  64. --------------------------------------------------
  65. GET my_index/_search
  66. {
  67. "query": {
  68. "match": {
  69. "manager.name": "Alice White"
  70. }
  71. },
  72. "aggs": {
  73. "Employees": {
  74. "nested": {
  75. "path": "employees"
  76. },
  77. "aggs": {
  78. "Employee Ages": {
  79. "histogram": {
  80. "field": "employees.age",
  81. "interval": 5
  82. }
  83. }
  84. }
  85. }
  86. }
  87. }
  88. --------------------------------------------------
  89. // TEST[continued]
  90. IMPORTANT: The full path to the inner field must be specified.