2013-08-28 19:24:34 -04:00
|
|
|
[[indices-create-index]]
|
|
|
|
== Create Index
|
|
|
|
|
2014-01-06 15:58:46 -05:00
|
|
|
The create index API allows to instantiate an index. Elasticsearch
|
2013-08-28 19:24:34 -04:00
|
|
|
provides support for multiple indices, including executing operations
|
2014-01-27 11:09:46 -05:00
|
|
|
across several indices.
|
|
|
|
|
|
|
|
[float]
|
|
|
|
[[create-index-settings]]
|
|
|
|
=== Index Settings
|
|
|
|
|
|
|
|
Each index created can have specific settings
|
2013-08-28 19:24:34 -04:00
|
|
|
associated with it.
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
$ curl -XPUT 'http://localhost:9200/twitter/'
|
|
|
|
|
|
|
|
$ curl -XPUT 'http://localhost:9200/twitter/' -d '
|
|
|
|
index :
|
|
|
|
number_of_shards : 3
|
|
|
|
number_of_replicas : 2
|
|
|
|
'
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
The above second curl example shows how an index called `twitter` can be
|
|
|
|
created with specific settings for it using http://www.yaml.org[YAML].
|
|
|
|
In this case, creating an index with 3 shards, each with 2 replicas. The
|
|
|
|
index settings can also be defined with http://www.json.org[JSON]:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
$ curl -XPUT 'http://localhost:9200/twitter/' -d '{
|
|
|
|
"settings" : {
|
|
|
|
"index" : {
|
|
|
|
"number_of_shards" : 3,
|
|
|
|
"number_of_replicas" : 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}'
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
or more simplified
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
$ curl -XPUT 'http://localhost:9200/twitter/' -d '{
|
|
|
|
"settings" : {
|
|
|
|
"number_of_shards" : 3,
|
|
|
|
"number_of_replicas" : 2
|
|
|
|
}
|
|
|
|
}'
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
_Note you do not have to explicitly specify `index` section inside
|
2014-01-27 11:09:46 -05:00
|
|
|
`settings` section.
|
|
|
|
|
|
|
|
For more information regarding all the different index level settings
|
|
|
|
that can be set when creating an index, please check the
|
|
|
|
<<index-modules,index modules>> section.
|
|
|
|
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[float]
|
2013-09-25 12:17:40 -04:00
|
|
|
[[mappings]]
|
2013-08-28 19:24:34 -04:00
|
|
|
=== Mappings
|
|
|
|
|
|
|
|
The create index API allows to provide a set of one or more mappings:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
curl -XPOST localhost:9200/test -d '{
|
|
|
|
"settings" : {
|
|
|
|
"number_of_shards" : 1
|
|
|
|
},
|
|
|
|
"mappings" : {
|
|
|
|
"type1" : {
|
|
|
|
"_source" : { "enabled" : false },
|
|
|
|
"properties" : {
|
|
|
|
"field1" : { "type" : "string", "index" : "not_analyzed" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}'
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
[float]
|
2014-01-27 11:09:46 -05:00
|
|
|
[[warmers]]
|
|
|
|
=== Warmers
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2014-01-27 11:09:46 -05:00
|
|
|
The create index API allows also to provide a set of <<indices-warmers,warmers>>:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
curl -XPUT localhost:9200/test -d '{
|
|
|
|
"warmers" : {
|
|
|
|
"warmer_1" : {
|
|
|
|
"source" : {
|
|
|
|
"query" : {
|
|
|
|
...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}'
|
|
|
|
--------------------------------------------------
|
2014-01-28 04:47:40 -05:00
|
|
|
|
|
|
|
[float]
|
|
|
|
[[create-index-aliases]]
|
|
|
|
=== Aliases
|
|
|
|
|
|
|
|
coming[1.1.0]
|
|
|
|
|
|
|
|
The create index API allows also to provide a set of <<indices-aliases,aliases>>:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
curl -XPUT localhost:9200/test -d '{
|
|
|
|
"aliases" : {
|
|
|
|
"alias_1" : {},
|
|
|
|
"alias_2" : {
|
|
|
|
"filter" : {
|
|
|
|
"term" : {"user" : "kimchy" }
|
|
|
|
},
|
|
|
|
"routing" : "kimchy"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}'
|
|
|
|
--------------------------------------------------
|