This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 728
/
CreateIndexIntegrationTest.java
86 lines (73 loc) · 3.91 KB
/
CreateIndexIntegrationTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package io.searchbox.indices;
import io.searchbox.client.JestResult;
import io.searchbox.common.AbstractIntegrationTest;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest;
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.junit.Test;
import java.io.IOException;
import java.util.Map;
/**
* @author Dogukan Sonmez
*/
@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.SUITE, numDataNodes = 1)
public class CreateIndexIntegrationTest extends AbstractIntegrationTest {
@Test
public void createIndexWithDefaultSettings() throws IOException {
CreateIndex createIndex = new CreateIndex.Builder("newindex").build();
JestResult result = client.execute(createIndex);
assertTrue(result.getErrorMessage(), result.isSucceeded());
}
@Test
public void createIndexWithMapSettings() throws IOException {
String index = "anothernewindex";
final ImmutableSettings.Builder indexerSettings = ImmutableSettings.settingsBuilder();
indexerSettings.put("analysis.analyzer.events.type", "custom");
indexerSettings.put("analysis.analyzer.events.tokenizer", "standard");
indexerSettings.put("analysis.analyzer.events.filter", "snowball, standard, lowercase");
Map<String, String> expectedSettingsMap = indexerSettings.build().getAsMap();
CreateIndex createIndex = new CreateIndex.Builder(index)
.settings(expectedSettingsMap)
.build();
JestResult result = client.execute(createIndex);
assertTrue(result.getErrorMessage(), result.isSucceeded());
GetSettingsResponse settingsResponse =
client().admin().indices().getSettings(new GetSettingsRequest().indices(index)).actionGet();
assertNotNull(settingsResponse);
Settings actualSettingsMap = settingsResponse.getIndexToSettings().get(index);
for (Map.Entry<String, String> entry : expectedSettingsMap.entrySet()) {
String key = "index." + entry.getKey();
assertEquals(entry.getValue(), actualSettingsMap.get(key));
}
}
@Test
public void createIndexWithStringSettingsAndMapping() throws IOException {
String index = "stringyone";
String expectedType1Maping =
"\"_source\":{\"enabled\":false},\"properties\":{\"field1\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}";
String settingsJson = "{\n" +
" \"settings\" : {\n" +
" \"number_of_shards\" : 8\n" +
" },\n" +
" \"mappings\" : {\"type1\": {" + expectedType1Maping + "}}" +
"}";
CreateIndex createIndex = new CreateIndex.Builder(index)
.settings(settingsJson)
.build();
JestResult result = client.execute(createIndex);
assertTrue(result.getErrorMessage(), result.isSucceeded());
GetSettingsResponse settingsResponse =
client().admin().indices().getSettings(new GetSettingsRequest().indices(index)).actionGet();
assertNotNull(settingsResponse);
assertEquals("8", settingsResponse.getSetting(index, "index.number_of_shards"));
GetMappingsResponse mappingsResponse =
client().admin().indices().getMappings(new GetMappingsRequest().indices(index)).actionGet();
assertNotNull(mappingsResponse);
String actualType1Mapping = mappingsResponse.getMappings().get(index).get("type1").source().string();
assertTrue(actualType1Mapping.contains(expectedType1Maping));
}
}