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 729
/
GetMappingIntegrationTest.java
119 lines (98 loc) · 5.91 KB
/
GetMappingIntegrationTest.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package io.searchbox.indices;
import com.google.gson.JsonObject;
import io.searchbox.action.Action;
import io.searchbox.client.JestResult;
import io.searchbox.common.AbstractIntegrationTest;
import io.searchbox.indices.mapping.GetMapping;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESIntegTestCase;
import org.junit.Test;
/**
* @author cihat keser
*/
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 1)
public class GetMappingIntegrationTest extends AbstractIntegrationTest {
static final String INDEX_1_NAME = "book";
static final String INDEX_2_NAME = "video";
static final String CUSTOM_TYPE = "science-fiction";
@Test
public void testWithoutParameters() throws Exception {
createIndex(INDEX_1_NAME, INDEX_2_NAME);
AcknowledgedResponse putMappingResponse = client().admin().indices().putMapping(
new PutMappingRequest(INDEX_1_NAME)
.type(CUSTOM_TYPE)
.source("{\"science-fiction\":{\"properties\":{\"title\":{\"store\":true,\"type\":\"text\"}," +
"\"author\":{\"store\":true,\"type\":\"text\"}}}}", XContentType.JSON)
).actionGet();
assertTrue(putMappingResponse.isAcknowledged());
assertConcreteMappingsOnAll(INDEX_1_NAME, CUSTOM_TYPE, "title", "author");
RefreshResponse refreshResponse = client().admin().indices()
.refresh(new RefreshRequest(INDEX_1_NAME, INDEX_2_NAME)).actionGet();
assertEquals("All shards should have been refreshed", 0, refreshResponse.getFailedShards());
GetMapping getMapping = new GetMapping.Builder().build();
JestResult result = client.execute(getMapping);
assertTrue(result.getErrorMessage(), result.isSucceeded());
JsonObject resultJson = result.getJsonObject();
assertNotNull("GetMapping response JSON should include the index " + INDEX_1_NAME,
resultJson.getAsJsonObject(INDEX_1_NAME));
assertNotNull("GetMapping response JSON should include the index " + INDEX_2_NAME,
resultJson.getAsJsonObject(INDEX_2_NAME));
}
@Test
public void testWithSingleIndex() throws Exception {
createIndex(INDEX_1_NAME, INDEX_2_NAME);
AcknowledgedResponse putMappingResponse = client().admin().indices().putMapping(
new PutMappingRequest(INDEX_1_NAME)
.type(CUSTOM_TYPE)
.source("{\"science-fiction\":{\"properties\":{\"title\":{\"store\":true,\"type\":\"text\"}," +
"\"author\":{\"store\":true,\"type\":\"text\"}}}}", XContentType.JSON)
).actionGet();
assertTrue(putMappingResponse.isAcknowledged());
assertConcreteMappingsOnAll(INDEX_1_NAME, CUSTOM_TYPE, "title", "author");
RefreshResponse refreshResponse = client().admin().indices()
.refresh(new RefreshRequest(INDEX_1_NAME, INDEX_2_NAME)).actionGet();
assertEquals("All shards should have been refreshed", 0, refreshResponse.getFailedShards());
Action getMapping = new GetMapping.Builder().addIndex(INDEX_2_NAME).build();
JestResult result = client.execute(getMapping);
assertTrue(result.getErrorMessage(), result.isSucceeded());
System.out.println("result.getJsonString() = " + result.getJsonString());
JsonObject resultJson = result.getJsonObject();
assertNotNull("GetMapping response JSON should include the index " + INDEX_2_NAME,
resultJson.getAsJsonObject(INDEX_2_NAME));
}
@Test
public void testWithMultipleIndices() throws Exception {
createIndex(INDEX_1_NAME, INDEX_2_NAME, "irrelevant");
AcknowledgedResponse putMappingResponse = client().admin().indices().putMapping(
new PutMappingRequest(INDEX_1_NAME)
.type(CUSTOM_TYPE)
.source("{\"science-fiction\":{\"properties\":{\"title\":{\"store\":true,\"type\":\"text\"}," +
"\"author\":{\"store\":true,\"type\":\"text\"}}}}", XContentType.JSON)
).actionGet();
assertTrue(putMappingResponse.isAcknowledged());
putMappingResponse = client().admin().indices().putMapping(
new PutMappingRequest(INDEX_2_NAME)
.type(CUSTOM_TYPE)
.source("{\"science-fiction\":{\"properties\":{\"title\":{\"store\":false,\"type\":\"text\"}," +
"\"isbn\":{\"store\":true,\"type\":\"text\"}}}}", XContentType.JSON)
).actionGet();
assertTrue(putMappingResponse.isAcknowledged());
assertConcreteMappingsOnAll(INDEX_1_NAME, CUSTOM_TYPE, "title", "author");
assertConcreteMappingsOnAll(INDEX_2_NAME, CUSTOM_TYPE, "title", "isbn");
RefreshResponse refreshResponse = client().admin().indices()
.refresh(new RefreshRequest(INDEX_1_NAME, INDEX_2_NAME)).actionGet();
assertEquals("All shards should have been refreshed", 0, refreshResponse.getFailedShards());
Action getMapping = new GetMapping.Builder().addIndex(INDEX_2_NAME).addIndex(INDEX_1_NAME).build();
JestResult result = client.execute(getMapping);
assertTrue(result.getErrorMessage(), result.isSucceeded());
JsonObject resultJson = result.getJsonObject();
assertNotNull("GetMapping response JSON should include the index " + INDEX_1_NAME,
resultJson.getAsJsonObject(INDEX_1_NAME));
assertNotNull("GetMapping response JSON should include the index " + INDEX_2_NAME,
resultJson.getAsJsonObject(INDEX_2_NAME));
}
}