create-index.asciidoc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 you do not have to explicitly specify `index` section inside
  46. `settings` section.
  47. For more information regarding all the different index level settings
  48. that can be set when creating an index, please check the
  49. <<index-modules,index modules>> section.
  50. [float]
  51. [[mappings]]
  52. === Mappings
  53. The create index API allows to provide a set of one or more mappings:
  54. [source,js]
  55. --------------------------------------------------
  56. curl -XPOST localhost:9200/test -d '{
  57. "settings" : {
  58. "number_of_shards" : 1
  59. },
  60. "mappings" : {
  61. "type1" : {
  62. "_source" : { "enabled" : false },
  63. "properties" : {
  64. "field1" : { "type" : "string", "index" : "not_analyzed" }
  65. }
  66. }
  67. }
  68. }'
  69. --------------------------------------------------
  70. [float]
  71. [[warmers]]
  72. === Warmers
  73. The create index API allows also to provide a set of <<indices-warmers,warmers>>:
  74. [source,js]
  75. --------------------------------------------------
  76. curl -XPUT localhost:9200/test -d '{
  77. "warmers" : {
  78. "warmer_1" : {
  79. "source" : {
  80. "query" : {
  81. ...
  82. }
  83. }
  84. }
  85. }
  86. }'
  87. --------------------------------------------------