2013-08-28 19:24:34 -04:00
|
|
|
[[indices-put-mapping]]
|
|
|
|
== Put Mapping
|
|
|
|
|
2018-03-13 04:58:47 -04:00
|
|
|
The PUT mapping API allows you to add fields to an existing index or to change search only settings of existing fields.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2015-08-12 15:21:37 -04:00
|
|
|
PUT twitter <1>
|
2017-07-05 06:30:19 -04:00
|
|
|
{}
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-01-14 16:08:01 -05:00
|
|
|
PUT twitter/_mapping <2>
|
2015-08-12 15:21:37 -04:00
|
|
|
{
|
|
|
|
"properties": {
|
2017-07-05 06:30:19 -04:00
|
|
|
"email": {
|
|
|
|
"type": "keyword"
|
2015-08-12 15:21:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-05-09 09:42:23 -04:00
|
|
|
// CONSOLE
|
2019-01-14 16:08:01 -05:00
|
|
|
<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`.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-01-14 16:08:01 -05:00
|
|
|
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>>.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[float]
|
2015-08-12 15:21:37 -04:00
|
|
|
=== Multi-index
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2015-08-12 15:21:37 -04:00
|
|
|
The PUT mapping API can be applied to multiple indices with a single request.
|
2017-05-01 13:56:39 -04:00
|
|
|
For example, we can update the `twitter-1` and `twitter-2` mappings at the same time:
|
2015-08-12 15:21:37 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2017-05-01 13:56:39 -04:00
|
|
|
# Create the two indices
|
|
|
|
PUT twitter-1
|
|
|
|
PUT twitter-2
|
2015-08-12 15:21:37 -04:00
|
|
|
|
2017-05-01 13:56:39 -04:00
|
|
|
# Update both mappings
|
2019-01-14 16:08:01 -05:00
|
|
|
PUT /twitter-1,twitter-2/_mapping <1>
|
2017-05-01 13:56:39 -04:00
|
|
|
{
|
|
|
|
"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.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
|
2015-08-12 15:21:37 -04:00
|
|
|
[[updating-field-mappings]]
|
2013-08-28 19:24:34 -04:00
|
|
|
[float]
|
2015-08-12 15:21:37 -04:00
|
|
|
=== Updating field mappings
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2015-08-12 15:21:37 -04:00
|
|
|
In general, the mapping for existing fields cannot be updated. There are some
|
|
|
|
exceptions to this rule. For instance:
|
|
|
|
|
|
|
|
* new <<properties>> can be added to <<object>> fields.
|
2015-08-12 16:00:27 -04:00
|
|
|
* new <<multi-fields,multi-fields>> can be added to existing fields.
|
2015-08-12 15:21:37 -04:00
|
|
|
* the <<ignore-above>> parameter can be updated.
|
|
|
|
|
|
|
|
For example:
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[source,js]
|
2015-08-12 15:21:37 -04:00
|
|
|
-----------------------------------
|
2019-01-14 16:08:01 -05:00
|
|
|
PUT my_index?include_type_name=true <1>
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
2015-08-12 15:21:37 -04:00
|
|
|
"mappings": {
|
2017-12-14 11:47:53 -05:00
|
|
|
"_doc": {
|
2015-08-12 15:21:37 -04:00
|
|
|
"properties": {
|
|
|
|
"name": {
|
|
|
|
"properties": {
|
|
|
|
"first": {
|
2016-03-18 12:01:27 -04:00
|
|
|
"type": "text"
|
2015-08-12 15:21:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"user_id": {
|
2016-03-18 12:01:27 -04:00
|
|
|
"type": "keyword"
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
2015-08-12 15:21:37 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
2015-08-12 15:21:37 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
Make PUT and DELETE consistent for _mapping, _alias and _warmer
See issue #4071
PUT options for _mapping:
Single type can now be added with
`[PUT|POST] {index|_all|*|regex|blank}/[_mapping|_mappings]/type`
and
`[PUT|POST] {index|_all|*|regex|blank}/type/[_mapping|_mappings]`
PUT options for _warmer:
PUT with a single warmer can now be done with
`[PUT|POST] {index|_all|*|prefix*|blank}/{type|_all|*|prefix*|blank}/[_warmer|_warmers]/warmer_name`
PUT options for _alias:
Single alias can now be PUT with
`[PUT|POST] {index|_all|*|prefix*|blank}/[_alias|_aliases]/alias`
DELETE options _mapping:
Several mappings can be deleted at once by defining several indices and types with
`[DELETE] /{index}/{type}`
`[DELETE] /{index}/{type}/_mapping`
`[DELETE] /{index}/_mapping/{type}`
where
`index= * | _all | glob pattern | name1, name2, …`
`type= * | _all | glob pattern | name1, name2, …`
Alternatively, the keyword `_mapings` can be used.
DELETE options for _warmer:
Several warmers can be deleted at once by defining several indices and names with
`[DELETE] /{index}/_warmer/{type}`
where
`index= * | _all | glob pattern | name1, name2, …`
`type= * | _all | glob pattern | name1, name2, …`
Alternatively, the keyword `_warmers` can be used.
DELETE options for _alias:
Several aliases can be deleted at once by defining several indices and names with
`[DELETE] /{index}/_alias/{type}`
where
`index= * | _all | glob pattern | name1, name2, …`
`type= * | _all | glob pattern | name1, name2, …`
Alternatively, the keyword `_aliases` can be used.
2014-01-08 04:34:48 -05:00
|
|
|
|
2019-01-14 16:08:01 -05:00
|
|
|
PUT my_index/_mapping
|
2015-08-12 15:21:37 -04:00
|
|
|
{
|
|
|
|
"properties": {
|
|
|
|
"name": {
|
|
|
|
"properties": {
|
|
|
|
"last": { <2>
|
2016-03-18 12:01:27 -04:00
|
|
|
"type": "text"
|
2015-08-12 15:21:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"user_id": {
|
2016-03-18 12:01:27 -04:00
|
|
|
"type": "keyword",
|
2015-08-12 15:21:37 -04:00
|
|
|
"ignore_above": 100 <3>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-----------------------------------
|
2016-05-09 09:42:23 -04:00
|
|
|
// CONSOLE
|
2015-08-12 15:21:37 -04:00
|
|
|
<1> Create an index with a `first` field under the `name` <<object>> field, and a `user_id` field.
|
|
|
|
<2> Add a `last` field under the `name` object field.
|
|
|
|
<3> Update the `ignore_above` setting from its default of 0.
|
Make PUT and DELETE consistent for _mapping, _alias and _warmer
See issue #4071
PUT options for _mapping:
Single type can now be added with
`[PUT|POST] {index|_all|*|regex|blank}/[_mapping|_mappings]/type`
and
`[PUT|POST] {index|_all|*|regex|blank}/type/[_mapping|_mappings]`
PUT options for _warmer:
PUT with a single warmer can now be done with
`[PUT|POST] {index|_all|*|prefix*|blank}/{type|_all|*|prefix*|blank}/[_warmer|_warmers]/warmer_name`
PUT options for _alias:
Single alias can now be PUT with
`[PUT|POST] {index|_all|*|prefix*|blank}/[_alias|_aliases]/alias`
DELETE options _mapping:
Several mappings can be deleted at once by defining several indices and types with
`[DELETE] /{index}/{type}`
`[DELETE] /{index}/{type}/_mapping`
`[DELETE] /{index}/_mapping/{type}`
where
`index= * | _all | glob pattern | name1, name2, …`
`type= * | _all | glob pattern | name1, name2, …`
Alternatively, the keyword `_mapings` can be used.
DELETE options for _warmer:
Several warmers can be deleted at once by defining several indices and names with
`[DELETE] /{index}/_warmer/{type}`
where
`index= * | _all | glob pattern | name1, name2, …`
`type= * | _all | glob pattern | name1, name2, …`
Alternatively, the keyword `_warmers` can be used.
DELETE options for _alias:
Several aliases can be deleted at once by defining several indices and names with
`[DELETE] /{index}/_alias/{type}`
where
`index= * | _all | glob pattern | name1, name2, …`
`type= * | _all | glob pattern | name1, name2, …`
Alternatively, the keyword `_aliases` can be used.
2014-01-08 04:34:48 -05:00
|
|
|
|
2015-08-12 15:21:37 -04:00
|
|
|
Each <<mapping-params,mapping parameter>> specifies whether or not its setting
|
|
|
|
can be updated on an existing field.
|