create-index.asciidoc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. [[indices-create-index]]
  2. == Create Index
  3. The create index API allows to instantiate an index. Elasticsearch
  4. provides support for multiple indices, including executing operations
  5. across several indices.
  6. [float]
  7. [[create-index-settings]]
  8. === Index Settings
  9. Each index created can have specific settings
  10. associated with it.
  11. [source,js]
  12. --------------------------------------------------
  13. $ curl -XPUT 'http://localhost:9200/twitter/'
  14. $ curl -XPUT 'http://localhost:9200/twitter/' -d '
  15. index :
  16. number_of_shards : 3 <1>
  17. number_of_replicas : 2 <2>
  18. '
  19. --------------------------------------------------
  20. <1> Default for `number_of_shards` is 5
  21. <2> Default for `number_of_replicas` is 1 (ie one replica for each primary shard)
  22. The above second curl example shows how an index called `twitter` can be
  23. created with specific settings for it using http://www.yaml.org[YAML].
  24. In this case, creating an index with 3 shards, each with 2 replicas. The
  25. index settings can also be defined with http://www.json.org[JSON]:
  26. [source,js]
  27. --------------------------------------------------
  28. $ curl -XPUT 'http://localhost:9200/twitter/' -d '{
  29. "settings" : {
  30. "index" : {
  31. "number_of_shards" : 3,
  32. "number_of_replicas" : 2
  33. }
  34. }
  35. }'
  36. --------------------------------------------------
  37. or more simplified
  38. [source,js]
  39. --------------------------------------------------
  40. $ curl -XPUT 'http://localhost:9200/twitter/' -d '{
  41. "settings" : {
  42. "number_of_shards" : 3,
  43. "number_of_replicas" : 2
  44. }
  45. }'
  46. --------------------------------------------------
  47. [NOTE]
  48. You do not have to explicitly specify `index` section inside the
  49. `settings` section.
  50. For more information regarding all the different index level settings
  51. that can be set when creating an index, please check the
  52. <<index-modules,index modules>> section.
  53. [float]
  54. [[mappings]]
  55. === Mappings
  56. The create index API allows to provide a set of one or more mappings:
  57. [source,js]
  58. --------------------------------------------------
  59. curl -XPOST localhost:9200/test -d '{
  60. "settings" : {
  61. "number_of_shards" : 1
  62. },
  63. "mappings" : {
  64. "type1" : {
  65. "_source" : { "enabled" : false },
  66. "properties" : {
  67. "field1" : { "type" : "string", "index" : "not_analyzed" }
  68. }
  69. }
  70. }
  71. }'
  72. --------------------------------------------------
  73. [float]
  74. [[warmers]]
  75. === Warmers
  76. The create index API allows also to provide a set of <<indices-warmers,warmers>>:
  77. [source,js]
  78. --------------------------------------------------
  79. curl -XPUT localhost:9200/test -d '{
  80. "warmers" : {
  81. "warmer_1" : {
  82. "source" : {
  83. "query" : {
  84. ...
  85. }
  86. }
  87. }
  88. }
  89. }'
  90. --------------------------------------------------
  91. [float]
  92. [[create-index-aliases]]
  93. === Aliases
  94. The create index API allows also to provide a set of <<indices-aliases,aliases>>:
  95. [source,js]
  96. --------------------------------------------------
  97. curl -XPUT localhost:9200/test -d '{
  98. "aliases" : {
  99. "alias_1" : {},
  100. "alias_2" : {
  101. "filter" : {
  102. "term" : {"user" : "kimchy" }
  103. },
  104. "routing" : "kimchy"
  105. }
  106. }
  107. }'
  108. --------------------------------------------------
  109. [float]
  110. === Creation Date
  111. When an index is created, a timestamp is stored in the index metadata for the creation date. By
  112. default this it is automatically generated but it can also be specified using the
  113. `creation_date` parameter on the create index API:
  114. [source,js]
  115. --------------------------------------------------
  116. curl -XPUT localhost:9200/test -d '{
  117. "creation_date" : 1407751337000 <1>
  118. }'
  119. --------------------------------------------------
  120. <1> `creation_date` is set using epoch time in milliseconds.