create-index.asciidoc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. Each index created can have specific settings
  6. associated with it.
  7. [source,js]
  8. --------------------------------------------------
  9. $ curl -XPUT 'http://localhost:9200/twitter/'
  10. $ curl -XPUT 'http://localhost:9200/twitter/' -d '
  11. index :
  12. number_of_shards : 3
  13. number_of_replicas : 2
  14. '
  15. --------------------------------------------------
  16. The above second curl example shows how an index called `twitter` can be
  17. created with specific settings for it using http://www.yaml.org[YAML].
  18. In this case, creating an index with 3 shards, each with 2 replicas. The
  19. index settings can also be defined with http://www.json.org[JSON]:
  20. [source,js]
  21. --------------------------------------------------
  22. $ curl -XPUT 'http://localhost:9200/twitter/' -d '{
  23. "settings" : {
  24. "index" : {
  25. "number_of_shards" : 3,
  26. "number_of_replicas" : 2
  27. }
  28. }
  29. }'
  30. --------------------------------------------------
  31. or more simplified
  32. [source,js]
  33. --------------------------------------------------
  34. $ curl -XPUT 'http://localhost:9200/twitter/' -d '{
  35. "settings" : {
  36. "number_of_shards" : 3,
  37. "number_of_replicas" : 2
  38. }
  39. }'
  40. --------------------------------------------------
  41. _Note you do not have to explicitly specify `index` section inside
  42. `settings` section._
  43. [float]
  44. [[mappings]]
  45. === Mappings
  46. The create index API allows to provide a set of one or more mappings:
  47. [source,js]
  48. --------------------------------------------------
  49. curl -XPOST localhost:9200/test -d '{
  50. "settings" : {
  51. "number_of_shards" : 1
  52. },
  53. "mappings" : {
  54. "type1" : {
  55. "_source" : { "enabled" : false },
  56. "properties" : {
  57. "field1" : { "type" : "string", "index" : "not_analyzed" }
  58. }
  59. }
  60. }
  61. }'
  62. --------------------------------------------------
  63. [float]
  64. [[settings]]
  65. === Index Settings
  66. For more information regarding all the different index level settings
  67. that can be set when creating an index, please check the
  68. <<index-modules,index modules>> section.