Skip to content

Commit b0e6cc0

Browse files
author
Christoph Büscher
committed
Revert "[Docs] Fix Java Api index administration usage (#28133)"
This reverts commit 6cebdde.
1 parent ac0333d commit b0e6cc0

File tree

2 files changed

+48
-77
lines changed

2 files changed

+48
-77
lines changed

core/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@
2626
import org.elasticsearch.action.search.SearchResponse;
2727
import org.elasticsearch.action.support.ActiveShardCount;
2828
import org.elasticsearch.action.support.IndicesOptions;
29-
import org.elasticsearch.client.Client;
3029
import org.elasticsearch.cluster.ClusterState;
3130
import org.elasticsearch.cluster.metadata.IndexMetaData;
3231
import org.elasticsearch.cluster.metadata.MetaData;
3332
import org.elasticsearch.common.collect.ImmutableOpenMap;
3433
import org.elasticsearch.common.settings.Settings;
3534
import org.elasticsearch.common.unit.TimeValue;
36-
import org.elasticsearch.common.xcontent.XContentType;
3735
import org.elasticsearch.index.IndexNotFoundException;
3836
import org.elasticsearch.index.query.RangeQueryBuilder;
3937
import org.elasticsearch.test.ESIntegTestCase;
@@ -345,70 +343,4 @@ public void testIndexNameInResponse() {
345343

346344
assertEquals("Should have index name in response", "foo", response.index());
347345
}
348-
349-
/**
350-
* This test method is used to generate the Put Mapping Java Indices API documentation
351-
* at "docs/java-api/admin/indices/put-mapping.asciidoc" so the documentation gets tested
352-
* so that it compiles and runs without throwing errors at runtime.
353-
*/
354-
public void testPutMappingDocumentation() throws Exception {
355-
Client client = client();
356-
// tag::addMapping-create-index-request
357-
client.admin().indices().prepareCreate("twitter") // <1>
358-
.addMapping("tweet", "{\n" + // <2>
359-
" \"tweet\": {\n" +
360-
" \"properties\": {\n" +
361-
" \"message\": {\n" +
362-
" \"type\": \"text\"\n" +
363-
" }\n" +
364-
" }\n" +
365-
" }\n" +
366-
" }", XContentType.JSON)
367-
.get();
368-
// end::addMapping-create-index-request
369-
370-
// we need to delete in order to create a fresh new index with another type
371-
client.admin().indices().prepareDelete("twitter").get();
372-
client.admin().indices().prepareCreate("twitter").get();
373-
374-
// tag::putMapping-request-source
375-
client.admin().indices().preparePutMapping("twitter") // <1>
376-
.setType("user") // <2>
377-
.setSource("{\n" + // <3>
378-
" \"properties\": {\n" +
379-
" \"name\": {\n" +
380-
" \"type\": \"text\"\n" +
381-
" }\n" +
382-
" }\n" +
383-
"}", XContentType.JSON)
384-
.get();
385-
386-
// You can also provide the type in the source document
387-
client.admin().indices().preparePutMapping("twitter")
388-
.setType("user")
389-
.setSource("{\n" +
390-
" \"user\":{\n" + // <4>
391-
" \"properties\": {\n" +
392-
" \"name\": {\n" +
393-
" \"type\": \"text\"\n" +
394-
" }\n" +
395-
" }\n" +
396-
" }\n" +
397-
"}", XContentType.JSON)
398-
.get();
399-
// end::putMapping-request-source
400-
401-
// tag::putMapping-request-source-append
402-
client.admin().indices().preparePutMapping("twitter") // <1>
403-
.setType("user") // <2>
404-
.setSource("{\n" + // <3>
405-
" \"properties\": {\n" +
406-
" \"user_name\": {\n" +
407-
" \"type\": \"text\"\n" +
408-
" }\n" +
409-
" }\n" +
410-
"}", XContentType.JSON)
411-
.get();
412-
// end::putMapping-request-source-append
413-
}
414346
}

docs/java-api/admin/indices/put-mapping.asciidoc

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,54 @@
11
[[java-admin-indices-put-mapping]]
2-
:base-dir: {docdir}/../../core/src/test/java/org/elasticsearch/action/admin/indices/create
3-
42
==== Put Mapping
53

64
The PUT mapping API allows you to add a new type while creating an index:
75

8-
["source","java",subs="attributes,callouts,macros"]
6+
[source,java]
97
--------------------------------------------------
10-
include-tagged::{base-dir}/CreateIndexIT.java[addMapping-create-index-request]
8+
client.admin().indices().prepareCreate("twitter") <1>
9+
.addMapping("tweet", "{\n" + <2>
10+
" \"tweet\": {\n" +
11+
" \"properties\": {\n" +
12+
" \"message\": {\n" +
13+
" \"type\": \"text\"\n" +
14+
" }\n" +
15+
" }\n" +
16+
" }\n" +
17+
" }")
18+
.get();
1119
--------------------------------------------------
1220
<1> <<java-admin-indices-create-index,Creates an index>> called `twitter`
1321
<2> It also adds a `tweet` mapping type.
1422

1523

1624
The PUT mapping API also allows to add a new type to an existing index:
1725

18-
["source","java",subs="attributes,callouts,macros"]
26+
[source,java]
1927
--------------------------------------------------
20-
include-tagged::{base-dir}/CreateIndexIT.java[putMapping-request-source]
28+
client.admin().indices().preparePutMapping("twitter") <1>
29+
.setType("user") <2>
30+
.setSource("{\n" + <3>
31+
" \"properties\": {\n" +
32+
" \"name\": {\n" +
33+
" \"type\": \"text\"\n" +
34+
" }\n" +
35+
" }\n" +
36+
"}")
37+
.get();
38+
39+
// You can also provide the type in the source document
40+
client.admin().indices().preparePutMapping("twitter")
41+
.setType("user")
42+
.setSource("{\n" +
43+
" \"user\":{\n" + <4>
44+
" \"properties\": {\n" +
45+
" \"name\": {\n" +
46+
" \"type\": \"text\"\n" +
47+
" }\n" +
48+
" }\n" +
49+
" }\n" +
50+
"}")
51+
.get();
2152
--------------------------------------------------
2253
<1> Puts a mapping on existing index called `twitter`
2354
<2> Adds a `user` mapping type.
@@ -26,12 +57,20 @@ include-tagged::{base-dir}/CreateIndexIT.java[putMapping-request-source]
2657

2758
You can use the same API to update an existing mapping:
2859

29-
["source","java",subs="attributes,callouts,macros"]
60+
[source,java]
3061
--------------------------------------------------
31-
include-tagged::{base-dir}/CreateIndexIT.java[putMapping-request-source-append]
62+
client.admin().indices().preparePutMapping("twitter") <1>
63+
.setType("user") <2>
64+
.setSource("{\n" + <3>
65+
" \"properties\": {\n" +
66+
" \"user_name\": {\n" +
67+
" \"type\": \"text\"\n" +
68+
" }\n" +
69+
" }\n" +
70+
"}")
71+
.get();
3272
--------------------------------------------------
3373
<1> Puts a mapping on existing index called `twitter`
3474
<2> Updates the `user` mapping type.
3575
<3> This `user` has now a new field `user_name`
3676

37-
:base-dir!:

0 commit comments

Comments
 (0)