Skip to content

Commit 8a58df4

Browse files
author
Christoph Büscher
committed
Revert "[Docs] Fix Java Api index administration usage (#28133)"
This reverts commit 67c1f1c.
1 parent 409b3d2 commit 8a58df4

File tree

2 files changed

+48
-77
lines changed

2 files changed

+48
-77
lines changed

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!:

server/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
@@ -20,7 +20,6 @@
2020
package org.elasticsearch.action.admin.indices.create;
2121

2222
import com.carrotsearch.hppc.cursors.ObjectCursor;
23-
2423
import org.elasticsearch.ElasticsearchException;
2524
import org.elasticsearch.action.ActionListener;
2625
import org.elasticsearch.action.UnavailableShardsException;
@@ -29,15 +28,13 @@
2928
import org.elasticsearch.action.search.SearchResponse;
3029
import org.elasticsearch.action.support.ActiveShardCount;
3130
import org.elasticsearch.action.support.IndicesOptions;
32-
import org.elasticsearch.client.Client;
3331
import org.elasticsearch.cluster.ClusterState;
3432
import org.elasticsearch.cluster.metadata.IndexMetaData;
3533
import org.elasticsearch.cluster.metadata.MetaData;
3634
import org.elasticsearch.cluster.node.DiscoveryNode;
3735
import org.elasticsearch.common.collect.ImmutableOpenMap;
3836
import org.elasticsearch.common.settings.Settings;
3937
import org.elasticsearch.common.unit.TimeValue;
40-
import org.elasticsearch.common.xcontent.XContentType;
4138
import org.elasticsearch.env.NodeEnvironment;
4239
import org.elasticsearch.index.IndexNotFoundException;
4340
import org.elasticsearch.index.query.RangeQueryBuilder;
@@ -403,69 +400,4 @@ public Settings onNodeStopped(String nodeName) throws Exception {
403400
assertThat(e, hasToString(containsString("unknown setting [index.foo]")));
404401
}
405402

406-
/**
407-
* This test method is used to generate the Put Mapping Java Indices API documentation
408-
* at "docs/java-api/admin/indices/put-mapping.asciidoc" so the documentation gets tested
409-
* so that it compiles and runs without throwing errors at runtime.
410-
*/
411-
public void testPutMappingDocumentation() throws Exception {
412-
Client client = client();
413-
// tag::addMapping-create-index-request
414-
client.admin().indices().prepareCreate("twitter") // <1>
415-
.addMapping("tweet", "{\n" + // <2>
416-
" \"tweet\": {\n" +
417-
" \"properties\": {\n" +
418-
" \"message\": {\n" +
419-
" \"type\": \"text\"\n" +
420-
" }\n" +
421-
" }\n" +
422-
" }\n" +
423-
" }", XContentType.JSON)
424-
.get();
425-
// end::addMapping-create-index-request
426-
427-
// we need to delete in order to create a fresh new index with another type
428-
client.admin().indices().prepareDelete("twitter").get();
429-
client.admin().indices().prepareCreate("twitter").get();
430-
431-
// tag::putMapping-request-source
432-
client.admin().indices().preparePutMapping("twitter") // <1>
433-
.setType("user") // <2>
434-
.setSource("{\n" + // <3>
435-
" \"properties\": {\n" +
436-
" \"name\": {\n" +
437-
" \"type\": \"text\"\n" +
438-
" }\n" +
439-
" }\n" +
440-
"}", XContentType.JSON)
441-
.get();
442-
443-
// You can also provide the type in the source document
444-
client.admin().indices().preparePutMapping("twitter")
445-
.setType("user")
446-
.setSource("{\n" +
447-
" \"user\":{\n" + // <4>
448-
" \"properties\": {\n" +
449-
" \"name\": {\n" +
450-
" \"type\": \"text\"\n" +
451-
" }\n" +
452-
" }\n" +
453-
" }\n" +
454-
"}", XContentType.JSON)
455-
.get();
456-
// end::putMapping-request-source
457-
458-
// tag::putMapping-request-source-append
459-
client.admin().indices().preparePutMapping("twitter") // <1>
460-
.setType("user") // <2>
461-
.setSource("{\n" + // <3>
462-
" \"properties\": {\n" +
463-
" \"user_name\": {\n" +
464-
" \"type\": \"text\"\n" +
465-
" }\n" +
466-
" }\n" +
467-
"}", XContentType.JSON)
468-
.get();
469-
// end::putMapping-request-source-append
470-
}
471403
}

0 commit comments

Comments
 (0)