Skip to content

Commit f6b166f

Browse files
committed
Merge remote-tracking branch 'dakrone/forbid-simpleregex-in-index-name'
2 parents d4dec26 + 6030acb commit f6b166f

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public MetaDataCreateIndexService(Settings settings, ClusterService clusterServi
144144
this.activeShardsObserver = new ActiveShardsObserver(settings, clusterService, threadPool);
145145
}
146146

147-
public void validateIndexName(String index, ClusterState state) {
147+
public static void validateIndexName(String index, ClusterState state) {
148148
if (state.routingTable().hasIndex(index)) {
149149
throw new IndexAlreadyExistsException(state.routingTable().index(index).getIndex());
150150
}
@@ -157,8 +157,8 @@ public void validateIndexName(String index, ClusterState state) {
157157
if (index.contains("#")) {
158158
throw new InvalidIndexNameException(index, "must not contain '#'");
159159
}
160-
if (index.charAt(0) == '_') {
161-
throw new InvalidIndexNameException(index, "must not start with '_'");
160+
if (index.charAt(0) == '_' || index.charAt(0) == '-' || index.charAt(0) == '+') {
161+
throw new InvalidIndexNameException(index, "must not start with '_', '-', or '+'");
162162
}
163163
if (!index.toLowerCase(Locale.ROOT).equals(index)) {
164164
throw new InvalidIndexNameException(index, "must be lowercase");

core/src/main/java/org/elasticsearch/snapshots/RestoreService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public ClusterState execute(ClusterState currentState) {
257257
if (currentIndexMetaData == null) {
258258
// Index doesn't exist - create it and start recovery
259259
// Make sure that the index we are about to create has a validate name
260-
createIndexService.validateIndexName(renamedIndexName, currentState);
260+
MetaDataCreateIndexService.validateIndexName(renamedIndexName, currentState);
261261
createIndexService.validateIndexSettings(renamedIndexName, snapshotIndexMetaData.getSettings());
262262
IndexMetaData.Builder indexMdBuilder = IndexMetaData.builder(snapshotIndexMetaData).state(IndexMetaData.State.OPEN).index(renamedIndexName);
263263
indexMdBuilder.settings(Settings.builder().put(snapshotIndexMetaData.getSettings()).put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()));

core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexServiceTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ public void testValidateIndexName() throws Exception {
191191

192192
validateIndexName("index#name", "must not contain '#'");
193193

194-
validateIndexName("_indexname", "must not start with '_'");
194+
validateIndexName("_indexname", "must not start with '_', '-', or '+'");
195+
validateIndexName("-indexname", "must not start with '_', '-', or '+'");
196+
validateIndexName("+indexname", "must not start with '_', '-', or '+'");
195197

196198
validateIndexName("INDEXNAME", "must be lowercase");
197199

@@ -201,7 +203,7 @@ public void testValidateIndexName() throws Exception {
201203

202204
private void validateIndexName(String indexName, String errorMessage) {
203205
InvalidIndexNameException e = expectThrows(InvalidIndexNameException.class,
204-
() -> getCreateIndexService().validateIndexName(indexName, ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING
206+
() -> MetaDataCreateIndexService.validateIndexName(indexName, ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING
205207
.getDefault(Settings.EMPTY)).build()));
206208
assertThat(e.getMessage(), endsWith(errorMessage));
207209
}

docs/reference/migration/migrate_5_0/index-apis.asciidoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,11 @@ CPU usage can be obtained from `OsStats.Cpu#getPercent`.
4949

5050
Suggest stats exposed through `suggest` in indices stats has been merged
5151
with `search` stats. `suggest` stats is exposed as part of `search` stats.
52+
53+
==== Creating indices starting with '-' or '+'
54+
55+
Elasticsearch no longer allows indices to be created started with '-' or '+', so
56+
that the multi-index matching and expansion is not confused. It was previously
57+
possible (but a really bad idea) to create indices starting with a hyphen or
58+
plus sign. Any index already existing with these preceding characters will
59+
continue to work normally.

0 commit comments

Comments
 (0)