File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed
main/java/org/springframework/data/elasticsearch/core
test/java/org/springframework/data/elasticsearch/core Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,14 @@ public interface ElasticsearchOperations {
45
45
*/
46
46
<T > boolean createIndex (Class <T > clazz );
47
47
48
+ /**
49
+ * Create an index for given indexName
50
+ *
51
+ * @param indexName
52
+ */
53
+ boolean createIndex (String indexName );
54
+
55
+
48
56
/**
49
57
* Create mapping for a class
50
58
*
Original file line number Diff line number Diff line change @@ -117,6 +117,14 @@ public <T> boolean createIndex(Class<T> clazz) {
117
117
return createIndexIfNotCreated (clazz );
118
118
}
119
119
120
+ @ Override
121
+ public boolean createIndex (String indexName ) {
122
+ Assert .notNull (indexName , "No index defined for Query" );
123
+ return client .admin ().indices ()
124
+ .create (Requests .createIndexRequest (indexName ))
125
+ .actionGet ().isAcknowledged ();
126
+ }
127
+
120
128
@ Override
121
129
public <T > boolean putMapping (Class <T > clazz ) {
122
130
ElasticsearchPersistentEntity <T > persistentEntity = getPersistentEntityFor (clazz );
Original file line number Diff line number Diff line change @@ -1256,14 +1256,31 @@ public void shouldReturnCountForGivenSearchQueryWithGivenMultiIndices() {
1256
1256
private void cleanUpIndices () {
1257
1257
elasticsearchTemplate .deleteIndex ("test-index-1" );
1258
1258
elasticsearchTemplate .deleteIndex ("test-index-2" );
1259
+ elasticsearchTemplate .createIndex ("test-index-1" );
1260
+ elasticsearchTemplate .createIndex ("test-index-2" );
1261
+ elasticsearchTemplate .refresh ("test-index-1" , true );
1262
+ elasticsearchTemplate .refresh ("test-index-2" , true );
1263
+ }
1264
+
1265
+ /*
1266
+ DATAES-71
1267
+ */
1268
+ @ Test
1269
+ public void shouldCreatedIndexWithSpecifiedIndexName () {
1270
+ // given
1271
+ elasticsearchTemplate .deleteIndex ("test-index" );
1272
+ // when
1273
+ elasticsearchTemplate .createIndex ("test-index" );
1274
+ // then
1275
+ assertThat (elasticsearchTemplate .indexExists ("test-index" ), is (true ));
1259
1276
}
1260
1277
1261
1278
/*
1262
1279
DATAES-72
1263
1280
*/
1264
1281
@ Test
1265
1282
public void shouldDeleteIndexForSpecifiedIndexName () {
1266
- //given
1283
+ // given
1267
1284
elasticsearchTemplate .createIndex (SampleEntity .class );
1268
1285
elasticsearchTemplate .refresh (SampleEntity .class , true );
1269
1286
You can’t perform that action at this time.
0 commit comments