[Docs] Fix Java Api index administration usage (#28260)

The Java API documentation for index administration currenty is wrong because
the PutMappingRequestBuilder#setSource(Object... source) an
CreateIndexRequestBuilder#addMapping(String type, Object... source) methods
delegate to methods that check that the input arguments are valid key/value
pairs. This changes the docs so the java api code examples are included from
documentation integration tests so we detect compile and runtime issues earlier.

Closes #28131
This commit is contained in:
Christoph Büscher 2018-03-14 22:02:06 +01:00 committed by GitHub
parent aa01770302
commit ae912cbde4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 38 deletions

View file

@ -1,4 +1,5 @@
[[java-admin-indices-put-mapping]]
==== Put Mapping
The PUT mapping API allows you to add a new type while creating an index:
@ -13,32 +14,9 @@ include-tagged::{client-tests}/IndicesDocumentationIT.java[index-with-mapping]
The PUT mapping API also allows to add a new type to an existing index:
[source,java]
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
client.admin().indices().preparePutMapping("twitter") <1>
.setType("user") <2>
.setSource("{\n" + <3>
" \"properties\": {\n" +
" \"name\": {\n" +
" \"type\": \"text\"\n" +
" }\n" +
" }\n" +
"}")
.get();
// You can also provide the type in the source document
client.admin().indices().preparePutMapping("twitter")
.setType("user")
.setSource("{\n" +
" \"user\":{\n" + <4>
" \"properties\": {\n" +
" \"name\": {\n" +
" \"type\": \"text\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}")
.get();
include-tagged::{client-tests}/IndicesDocumentationIT.java[putMapping-request-source]
--------------------------------------------------
<1> Puts a mapping on existing index called `twitter`
<2> Adds a `user` mapping type.
@ -47,20 +25,12 @@ client.admin().indices().preparePutMapping("twitter")
You can use the same API to update an existing mapping:
[source,java]
["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
client.admin().indices().preparePutMapping("twitter") <1>
.setType("user") <2>
.setSource("{\n" + <3>
" \"properties\": {\n" +
" \"user_name\": {\n" +
" \"type\": \"text\"\n" +
" }\n" +
" }\n" +
"}")
.get();
include-tagged::{client-tests}/IndicesDocumentationIT.java[putMapping-request-source-append]
--------------------------------------------------
<1> Puts a mapping on existing index called `twitter`
<2> Updates the `user` mapping type.
<3> This `user` has now a new field `user_name`
:base-dir!: