|
@@ -19,10 +19,19 @@
|
|
|
|
|
|
package org.elasticsearch.client.documentation;
|
|
|
|
|
|
+import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
|
|
|
import org.elasticsearch.client.Client;
|
|
|
+import org.elasticsearch.cluster.metadata.MappingMetaData;
|
|
|
+import org.elasticsearch.common.collect.ImmutableOpenMap;
|
|
|
import org.elasticsearch.common.xcontent.XContentType;
|
|
|
import org.elasticsearch.test.ESIntegTestCase;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import static java.util.Collections.singletonMap;
|
|
|
+import static org.hamcrest.Matchers.instanceOf;
|
|
|
+
|
|
|
/**
|
|
|
* This class is used to generate the Java indices administration documentation.
|
|
|
* You need to wrap your code between two tags like:
|
|
@@ -48,16 +57,14 @@ public class IndicesDocumentationIT extends ESIntegTestCase {
|
|
|
Client client = client();
|
|
|
|
|
|
// tag::index-with-mapping
|
|
|
- client.admin().indices().prepareCreate("twitter") // <1>
|
|
|
- .addMapping("\"tweet\": {\n" + // <2>
|
|
|
- " \"properties\": {\n" +
|
|
|
- " \"message\": {\n" +
|
|
|
- " \"type\": \"text\"\n" +
|
|
|
- " }\n" +
|
|
|
- " }\n" +
|
|
|
- "}")
|
|
|
+ client.admin().indices().prepareCreate("twitter") // <1>
|
|
|
+ .addMapping("tweet", "message", "type=text") // <2>
|
|
|
.get();
|
|
|
// end::index-with-mapping
|
|
|
+ GetMappingsResponse getMappingsResponse = client.admin().indices().prepareGetMappings("twitter").get();
|
|
|
+ assertEquals(1, getMappingsResponse.getMappings().size());
|
|
|
+ ImmutableOpenMap<String, MappingMetaData> indexMapping = getMappingsResponse.getMappings().get("twitter");
|
|
|
+ assertThat(indexMapping.get("tweet"), instanceOf(MappingMetaData.class));
|
|
|
|
|
|
// we need to delete in order to create a fresh new index with another type
|
|
|
client.admin().indices().prepareDelete("twitter").get();
|
|
@@ -89,6 +96,11 @@ public class IndicesDocumentationIT extends ESIntegTestCase {
|
|
|
"}", XContentType.JSON)
|
|
|
.get();
|
|
|
// end::putMapping-request-source
|
|
|
+ getMappingsResponse = client.admin().indices().prepareGetMappings("twitter").get();
|
|
|
+ assertEquals(1, getMappingsResponse.getMappings().size());
|
|
|
+ indexMapping = getMappingsResponse.getMappings().get("twitter");
|
|
|
+ assertEquals(singletonMap("properties", singletonMap("name", singletonMap("type", "text"))),
|
|
|
+ indexMapping.get("user").getSourceAsMap());
|
|
|
|
|
|
// tag::putMapping-request-source-append
|
|
|
client.admin().indices().preparePutMapping("twitter") // <1>
|
|
@@ -102,6 +114,13 @@ public class IndicesDocumentationIT extends ESIntegTestCase {
|
|
|
"}", XContentType.JSON)
|
|
|
.get();
|
|
|
// end::putMapping-request-source-append
|
|
|
+ getMappingsResponse = client.admin().indices().prepareGetMappings("twitter").get();
|
|
|
+ assertEquals(1, getMappingsResponse.getMappings().size());
|
|
|
+ indexMapping = getMappingsResponse.getMappings().get("twitter");
|
|
|
+ Map<String, Map<?,?>> expected = new HashMap<>();
|
|
|
+ expected.put("name", singletonMap("type", "text"));
|
|
|
+ expected.put("user_name", singletonMap("type", "text"));
|
|
|
+ assertEquals(expected, indexMapping.get("user").getSourceAsMap().get("properties"));
|
|
|
}
|
|
|
|
|
|
}
|