Skip to content

Commit 0c7619c

Browse files
committed
start on create index from source
1 parent 1c66cdc commit 0c7619c

File tree

1 file changed

+256
-0
lines changed

1 file changed

+256
-0
lines changed
Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
[[indices-create-index-from-source]]
2+
=== Create index from source API
3+
++++
4+
<titleabbrev>Create index from source</titleabbrev>
5+
++++
6+
7+
.New API reference
8+
[sidebar]
9+
--
10+
For the most up-to-date API details, refer to {api-es}/group/endpoint-indices[Index APIs].
11+
--
12+
13+
Creates a new index.
14+
15+
[source,console]
16+
--------------------------------------------------
17+
POST /_create_from/my-index/another-index/
18+
--------------------------------------------------
19+
20+
[[indices-create-index-from-source-api-request]]
21+
==== {api-request-title}
22+
23+
`PUT /_create_from/<source>/<dest>`
24+
25+
`POST/_create_from/<source>/<dest>`
26+
27+
[[indices-create-index-from-source-api-prereqs]]
28+
==== {api-prereq-title}
29+
30+
* If the {es} {security-features} are enabled, you must have the `create_index`
31+
or `manage` <<privileges-list-indices,index privilege>> for the target index. To
32+
add the index to an alias, you must have the `manage` index privilege for the
33+
alias.
34+
35+
[[indices-create-index-from-source-api-desc]]
36+
==== {api-description-title}
37+
This api allows you to add a new index to an {es} cluster, using an existing source index as a basis for the new index.
38+
The settings and mappings from the source index will copied over to the destination index. You can also provide
39+
override settings and mappings which will be combined with the source settings and mappings when creating the
40+
destination index.
41+
42+
[[indices-create-index-from-source-api-path-params]]
43+
==== {api-path-parms-title}
44+
45+
`<source>`::
46+
(Required, string) Name of the existing source index which will be used as a basis.
47+
48+
`<dest>`::
49+
(Required, string) Name of the destination index which will be created.
50+
51+
52+
53+
[role="child_attributes"]
54+
[[indices-create-api-request-body]]
55+
==== {api-request-body-title}
56+
57+
`aliases`::
58+
(Optional, object of objects) Aliases for the index.
59+
+
60+
--
61+
// tag::aliases-props[]
62+
[%collapsible%open]
63+
.Properties of `aliases` objects
64+
=======
65+
`<alias>`::
66+
(Required, object) The key is the alias name. Index alias names support
67+
<<api-date-math-index-names,date math>>.
68+
+
69+
The object body contains options for the alias. Supports an empty object.
70+
+
71+
.Properties of `<alias>`
72+
[%collapsible%open]
73+
======
74+
`filter`::
75+
(Optional, <<query-dsl,Query DSL object>>) Query used to limit documents the
76+
alias can access.
77+
78+
`index_routing`::
79+
(Optional, string) Value used to route indexing operations to a specific shard.
80+
If specified, this overwrites the `routing` value for indexing operations.
81+
82+
`is_hidden`::
83+
(Optional, Boolean) If `true`, the alias is <<multi-hidden,hidden>>. Defaults to
84+
`false`. All indices for the alias must have the same `is_hidden` value.
85+
86+
`is_write_index`::
87+
(Optional, Boolean) If `true`, the index is the <<write-index,write index>> for
88+
the alias. Defaults to `false`.
89+
90+
`routing`::
91+
(Optional, string) Value used to route indexing and search operations to a
92+
specific shard.
93+
94+
`search_routing`::
95+
(Optional, string) Value used to route search operations to a specific shard. If
96+
specified, this overwrites the `routing` value for search operations.
97+
======
98+
=======
99+
// end::aliases-props[]
100+
--
101+
102+
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=mappings]
103+
104+
include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=settings]
105+
106+
[[indices-create-api-example]]
107+
==== {api-examples-title}
108+
109+
[[create-index-settings]]
110+
===== Index settings
111+
112+
Each index created can have specific settings
113+
associated with it, defined in the body:
114+
115+
[source,console]
116+
--------------------------------------------------
117+
PUT /my-index-000001
118+
{
119+
"settings": {
120+
"index": {
121+
"number_of_shards": 3, <1>
122+
"number_of_replicas": 2 <2>
123+
}
124+
}
125+
}
126+
--------------------------------------------------
127+
128+
<1> Default for `number_of_shards` is 1
129+
<2> Default for `number_of_replicas` is 1 (ie one replica for each primary shard)
130+
131+
or more simplified
132+
133+
[source,console]
134+
--------------------------------------------------
135+
PUT /my-index-000001
136+
{
137+
"settings": {
138+
"number_of_shards": 3,
139+
"number_of_replicas": 2
140+
}
141+
}
142+
--------------------------------------------------
143+
144+
[NOTE]
145+
You do not have to explicitly specify `index` section inside the
146+
`settings` section.
147+
148+
For more information regarding all the different index level settings
149+
that can be set when creating an index, please check the
150+
<<index-modules,index modules>> section.
151+
152+
[[mappings]]
153+
===== Mappings
154+
155+
The create index API allows for providing a mapping definition:
156+
157+
[source,console]
158+
--------------------------------------------------
159+
PUT /test
160+
{
161+
"settings": {
162+
"number_of_shards": 1
163+
},
164+
"mappings": {
165+
"properties": {
166+
"field1": { "type": "text" }
167+
}
168+
}
169+
}
170+
--------------------------------------------------
171+
172+
[[create-index-aliases]]
173+
===== Aliases
174+
175+
The create index API allows also to provide a set of <<aliases,aliases>>:
176+
177+
[source,console]
178+
--------------------------------------------------
179+
PUT /test
180+
{
181+
"aliases": {
182+
"alias_1": {},
183+
"alias_2": {
184+
"filter": {
185+
"term": { "user.id": "kimchy" }
186+
},
187+
"routing": "shard-1"
188+
}
189+
}
190+
}
191+
--------------------------------------------------
192+
193+
Index alias names also support <<api-date-math-index-names,date math>>.
194+
195+
[source,console]
196+
----
197+
PUT /logs
198+
{
199+
"aliases": {
200+
"<logs_{now/M}>": {}
201+
}
202+
}
203+
----
204+
205+
[[create-index-wait-for-active-shards]]
206+
===== Wait for active shards
207+
208+
By default, index creation will only return a response to the client when the primary copies of
209+
each shard have been started, or the request times out. The index creation response will indicate
210+
what happened:
211+
212+
[source,console-result]
213+
--------------------------------------------------
214+
{
215+
"acknowledged": true,
216+
"shards_acknowledged": true,
217+
"index": "logs"
218+
}
219+
--------------------------------------------------
220+
221+
`acknowledged` indicates whether the index was successfully created in the cluster, while
222+
`shards_acknowledged` indicates whether the requisite number of shard copies were started for
223+
each shard in the index before timing out. Note that it is still possible for either
224+
`acknowledged` or `shards_acknowledged` to be `false`, but the index creation was successful.
225+
These values simply indicate whether the operation completed before the timeout. If
226+
`acknowledged` is `false`, then we timed out before the cluster state was updated with the
227+
newly created index, but it probably will be created sometime soon. If `shards_acknowledged`
228+
is `false`, then we timed out before the requisite number of shards were started (by default
229+
just the primaries), even if the cluster state was successfully updated to reflect the newly
230+
created index (i.e. `acknowledged=true`).
231+
232+
We can change the default of only waiting for the primary shards to start through the index
233+
setting `index.write.wait_for_active_shards` (note that changing this setting will also affect
234+
the `wait_for_active_shards` value on all subsequent write operations):
235+
236+
[source,console]
237+
--------------------------------------------------
238+
PUT /test
239+
{
240+
"settings": {
241+
"index.write.wait_for_active_shards": "2"
242+
}
243+
}
244+
--------------------------------------------------
245+
// TEST[skip:requires two nodes]
246+
247+
or through the request parameter `wait_for_active_shards`:
248+
249+
[source,console]
250+
--------------------------------------------------
251+
PUT /test?wait_for_active_shards=2
252+
--------------------------------------------------
253+
// TEST[skip:requires two nodes]
254+
255+
A detailed explanation of `wait_for_active_shards` and its possible values can be found
256+
<<index-wait-for-active-shards,here>>.

0 commit comments

Comments
 (0)