create-index.asciidoc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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
  17. number_of_replicas : 2
  18. '
  19. --------------------------------------------------
  20. The above second curl example shows how an index called `twitter` can be
  21. created with specific settings for it using http://www.yaml.org[YAML].
  22. In this case, creating an index with 3 shards, each with 2 replicas. The
  23. index settings can also be defined with http://www.json.org[JSON]:
  24. [source,js]
  25. --------------------------------------------------
  26. $ curl -XPUT 'http://localhost:9200/twitter/' -d '{
  27. "settings" : {
  28. "index" : {
  29. "number_of_shards" : 3,
  30. "number_of_replicas" : 2
  31. }
  32. }
  33. }'
  34. --------------------------------------------------
  35. or more simplified
  36. [source,js]
  37. --------------------------------------------------
  38. $ curl -XPUT 'http://localhost:9200/twitter/' -d '{
  39. "settings" : {
  40. "number_of_shards" : 3,
  41. "number_of_replicas" : 2
  42. }
  43. }'
  44. --------------------------------------------------
  45. [NOTE]
  46. You do not have to explicitly specify `index` section inside the
  47. `settings` section.
  48. For more information regarding all the different index level settings
  49. that can be set when creating an index, please check the
  50. <<index-modules,index modules>> section.
  51. [float]
  52. [[mappings]]
  53. === Mappings
  54. The create index API allows to provide a set of one or more mappings:
  55. [source,js]
  56. --------------------------------------------------
  57. curl -XPOST localhost:9200/test -d '{
  58. "settings" : {
  59. "number_of_shards" : 1
  60. },
  61. "mappings" : {
  62. "type1" : {
  63. "_source" : { "enabled" : false },
  64. "properties" : {
  65. "field1" : { "type" : "string", "index" : "not_analyzed" }
  66. }
  67. }
  68. }
  69. }'
  70. --------------------------------------------------
  71. [float]
  72. [[warmers]]
  73. === Warmers
  74. The create index API allows also to provide a set of <<indices-warmers,warmers>>:
  75. [source,js]
  76. --------------------------------------------------
  77. curl -XPUT localhost:9200/test -d '{
  78. "warmers" : {
  79. "warmer_1" : {
  80. "source" : {
  81. "query" : {
  82. ...
  83. }
  84. }
  85. }
  86. }
  87. }'
  88. --------------------------------------------------
  89. [float]
  90. [[create-index-aliases]]
  91. === Aliases
  92. coming[1.1.0]
  93. The create index API allows also to provide a set of <<indices-aliases,aliases>>:
  94. [source,js]
  95. --------------------------------------------------
  96. curl -XPUT localhost:9200/test -d '{
  97. "aliases" : {
  98. "alias_1" : {},
  99. "alias_2" : {
  100. "filter" : {
  101. "term" : {"user" : "kimchy" }
  102. },
  103. "routing" : "kimchy"
  104. }
  105. }
  106. }'
  107. --------------------------------------------------