properties.asciidoc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. "_doc": { <1>
  18. "properties": {
  19. "manager": { <2>
  20. "properties": {
  21. "age": { "type": "integer" },
  22. "name": { "type": "text" }
  23. }
  24. },
  25. "employees": { <3>
  26. "type": "nested",
  27. "properties": {
  28. "age": { "type": "integer" },
  29. "name": { "type": "text" }
  30. }
  31. }
  32. }
  33. }
  34. }
  35. }
  36. PUT my_index/_doc/1 <4>
  37. {
  38. "region": "US",
  39. "manager": {
  40. "name": "Alice White",
  41. "age": 30
  42. },
  43. "employees": [
  44. {
  45. "name": "John Smith",
  46. "age": 34
  47. },
  48. {
  49. "name": "Peter Brown",
  50. "age": 26
  51. }
  52. ]
  53. }
  54. --------------------------------------------------
  55. // CONSOLE
  56. <1> Properties under the `_doc` mapping type.
  57. <2> Properties under the `manager` object field.
  58. <3> Properties under the `employees` nested field.
  59. <4> An example document which corresponds to the above mapping.
  60. TIP: The `properties` setting is allowed to have different settings for fields
  61. of the same name in the same index. New properties can be added to existing
  62. fields using the <<indices-put-mapping,PUT mapping API>>.
  63. ==== Dot notation
  64. Inner fields can be referred to in queries, aggregations, etc., using _dot
  65. notation_:
  66. [source,js]
  67. --------------------------------------------------
  68. GET my_index/_search
  69. {
  70. "query": {
  71. "match": {
  72. "manager.name": "Alice White"
  73. }
  74. },
  75. "aggs": {
  76. "Employees": {
  77. "nested": {
  78. "path": "employees"
  79. },
  80. "aggs": {
  81. "Employee Ages": {
  82. "histogram": {
  83. "field": "employees.age",
  84. "interval": 5
  85. }
  86. }
  87. }
  88. }
  89. }
  90. }
  91. --------------------------------------------------
  92. // CONSOLE
  93. // TEST[continued]
  94. IMPORTANT: The full path to the inner field must be specified.