Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOCS] Reformat put mapping API docs #45709

Merged
merged 4 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 127 additions & 39 deletions docs/reference/indices/put-mapping.asciidoc
Original file line number Diff line number Diff line change
@@ -1,61 +1,48 @@
[[indices-put-mapping]]
=== Put Mapping
=== Put mapping API
++++
<titleabbrev>Put mapping</titleabbrev>
++++

The PUT mapping API allows you to add fields to an existing index or to change search only settings of existing fields.
Adds new fields to an existing index or changes the search settings of existing
fields.

[source,js]
--------------------------------------------------
PUT twitter <1>
{}

PUT twitter/_mapping <2>
----
PUT /twitter/_mapping
{
"properties": {
"email": {
"type": "keyword"
}
}
}
--------------------------------------------------
----
// CONSOLE
<1> <<indices-create-index,Creates an index>> called `twitter` without any mapping.
<2> Uses the PUT mapping API to add a new field called `email`.
// TEST[setup:twitter]

More information on how to define mappings can be found in the <<mapping,mapping>> section.
NOTE: Before 7.0.0, the 'mappings' definition used to include a type name.
Although specifying types in requests is now deprecated, a type can still be
provided if the request parameter `include_type_name` is set. For more details,
please see <<removal-of-types>>.

NOTE: Before 7.0.0, the 'mappings' definition used to include a type name. Although specifying
types in requests is now deprecated, a type can still be provided if the request parameter
include_type_name is set. For more details, please see <<removal-of-types>>.

[float]
==== Multi-index
[[put-mapping-api-request]]
==== {api-request-title}

The PUT mapping API can be applied to multiple indices with a single request.
For example, we can update the `twitter-1` and `twitter-2` mappings at the same time:
`PUT /{index}/_mapping`

[source,js]
--------------------------------------------------
# Create the two indices
PUT twitter-1
PUT twitter-2
`PUT /_mapping`

# Update both mappings
PUT /twitter-1,twitter-2/_mapping <1>
{
"properties": {
"user_name": {
"type": "text"
}
}
}
--------------------------------------------------
// CONSOLE
<1> Note that the indices specified (`twitter-1,twitter-2`) follows <<multi-index,multiple index names>> and wildcard format.

[[put-mapping-api-desc]]
==== {api-description-title}

You can use the put mapping API to add fields to an existing index or to change
the search settings of existing fields.

[[updating-field-mappings]]
[float]
==== Updating field mappings
===== Restrictions for existing fields

// tag::put-field-mapping-exceptions[]

Expand All @@ -75,11 +62,112 @@ you only want to rename a field, consider adding an <<alias, `alias`>> field.

// end::put-field-mapping-exceptions[]


[[put-mapping-api-path-params]]
==== {api-path-parms-title}

include::{docdir}/rest-api/common-parms.asciidoc[tag=index]
+
To update the mapping of all indices, omit this parameter or use a value of
`_all`.


[[put-mapping-api-query-params]]
==== {api-query-parms-title}

include::{docdir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]

include::{docdir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
+
Defaults to `open`.

include::{docdir}/rest-api/common-parms.asciidoc[tag=include-type-name]

include::{docdir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]

include::{docdir}/rest-api/common-parms.asciidoc[tag=timeoutparms]


[[put-mapping-api-request-body]]
==== {api-request-body-title}

`properties`::
+
--
(Required, <<mapping,mapping object>>) Mapping for a field. For new
fields, this mapping can include:

* Field name
* <<field-datatypes,Field datatype>>
* <<mapping-params,Mapping parameters>>

For existing fields, see <<updating-field-mappings>>.
--


[[put-mapping-api-example]]
==== {api-examples-title}

[[put-field-mapping-api-basic-ex]]
===== Example with index setup

The put mapping API requires an existing index. The following
<<indices-create-index, create index>> API request creates the `publications`
index with no mapping.

[source,js]
----
PUT /publications
----
// CONSOLE

The following put mapping API request adds `title`, a new <<text,`text`>> field,
to the `publications` index.

[source,js]
----
PUT /publications/_mapping
{
"properties": {
"title": { "type": "text"}
}
}
----
// CONSOLE
// TEST[continued]

[[put-mapping-api-multi-ex]]
===== Multiple indices

The PUT mapping API can be applied to multiple indices with a single request.
For example, we can update the `twitter-1` and `twitter-2` mappings at the same time:

[source,js]
--------------------------------------------------
# Create the two indices
PUT /twitter-1
PUT /twitter-2

# Update both mappings
PUT /twitter-1,twitter-2/_mapping <1>
{
"properties": {
"user_name": {
"type": "text"
}
}
}
--------------------------------------------------
// CONSOLE
// TEST[setup:twitter]

<1> Note that the indices specified (`twitter-1,twitter-2`) follows <<multi-index,multiple index names>> and wildcard format.

For example:

[source,js]
-----------------------------------
PUT my_index <1>
PUT /my_index <1>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is strange to have "For example:" sentence on line 166 and an example below in this section of the document. Before it was showing an example for updating mapping of the existing documents. Now it ended up in the section "Multiple indices". I think we need to move these examples under the section "Restrictions for existing fields"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this @mayya-sharipova. It looks like I mangled the attempt to move this under the description section.

With35e9d82, I moved info about updating existing mappings back to the examples section.

{
"mappings": {
"properties": {
Expand All @@ -97,7 +185,7 @@ PUT my_index <1>
}
}

PUT my_index/_mapping
PUT /my_index/_mapping
{
"properties": {
"name": {
Expand Down
1 change: 1 addition & 0 deletions docs/reference/mapping.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ document.


[float]
[[field-datatypes]]
== Field datatypes

Each field has a data `type` which can be:
Expand Down