properties.asciidoc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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,js]
  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. // CONSOLE
  54. <1> Properties in the top-level mappings definition.
  55. <2> Properties under the `manager` object field.
  56. <3> Properties under the `employees` nested field.
  57. <4> An example document which corresponds to the above mapping.
  58. TIP: The `properties` setting is allowed to have different settings for fields
  59. of the same name in the same index. New properties can be added to existing
  60. fields using the <<indices-put-mapping,PUT mapping API>>.
  61. ==== Dot notation
  62. Inner fields can be referred to in queries, aggregations, etc., using _dot
  63. notation_:
  64. [source,js]
  65. --------------------------------------------------
  66. GET my_index/_search
  67. {
  68. "query": {
  69. "match": {
  70. "manager.name": "Alice White"
  71. }
  72. },
  73. "aggs": {
  74. "Employees": {
  75. "nested": {
  76. "path": "employees"
  77. },
  78. "aggs": {
  79. "Employee Ages": {
  80. "histogram": {
  81. "field": "employees.age",
  82. "interval": 5
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }
  89. --------------------------------------------------
  90. // CONSOLE
  91. // TEST[continued]
  92. IMPORTANT: The full path to the inner field must be specified.