2013-08-28 19:24:34 -04:00
|
|
|
[[indices-put-mapping]]
|
|
|
|
== Put Mapping
|
|
|
|
|
2016-11-26 06:43:56 -05:00
|
|
|
The PUT mapping API allows you to add a new type to an existing index, or add new
|
2015-08-12 15:21:37 -04:00
|
|
|
fields to an existing type:
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2015-08-12 15:21:37 -04:00
|
|
|
PUT twitter <1>
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
2015-08-12 15:21:37 -04:00
|
|
|
"mappings": {
|
|
|
|
"tweet": {
|
|
|
|
"properties": {
|
|
|
|
"message": {
|
2016-03-18 12:01:27 -04:00
|
|
|
"type": "text"
|
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
|
|
|
}
|
|
|
|
|
2015-08-12 15:21:37 -04:00
|
|
|
PUT twitter/_mapping/user <2>
|
|
|
|
{
|
|
|
|
"properties": {
|
|
|
|
"name": {
|
2016-03-18 12:01:27 -04:00
|
|
|
"type": "text"
|
2015-08-12 15:21:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PUT twitter/_mapping/tweet <3>
|
|
|
|
{
|
|
|
|
"properties": {
|
|
|
|
"user_name": {
|
2016-03-18 12:01:27 -04:00
|
|
|
"type": "text"
|
2015-08-12 15:21:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-05-09 09:42:23 -04:00
|
|
|
// CONSOLE
|
2015-08-12 15:21:37 -04:00
|
|
|
<1> <<indices-create-index,Creates an index>> called `twitter` with the `message` field in the `tweet` <<mapping-type,mapping type>>.
|
|
|
|
<2> Uses the PUT mapping API to add a new mapping type called `user`.
|
|
|
|
<3> Uses the PUT mapping API to add a new field called `user_name` to the `tweet` mapping type.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
More information on how to define type mappings can be found in the
|
|
|
|
<<mapping,mapping>> section.
|
|
|
|
|
|
|
|
[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.
|
|
|
|
It has the following format:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
PUT /{index}/_mapping/{type}
|
|
|
|
{ body }
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
* `{index}` accepts <<multi-index,multiple index names>> and wildcards.
|
|
|
|
* `{type}` is the name of the type to update.
|
|
|
|
* `{body}` contains the mapping changes that should be applied.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
|
2016-11-26 06:43:56 -05:00
|
|
|
NOTE: When updating the `_default_` mapping with the
|
|
|
|
<<indices-put-mapping,PUT mapping>> API, the new mapping is not merged with
|
|
|
|
the existing mapping. Instead, the new `_default_` mapping replaces the
|
|
|
|
existing one.
|
|
|
|
|
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
|
|
|
* <<doc-values>> can be disabled, but not enabled.
|
|
|
|
* 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
|
|
|
-----------------------------------
|
|
|
|
PUT my_index <1>
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
2015-08-12 15:21:37 -04:00
|
|
|
"mappings": {
|
|
|
|
"user": {
|
|
|
|
"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
|
|
|
|
2015-10-30 13:17:40 -04:00
|
|
|
PUT my_index/_mapping/user
|
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.
|
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
|
|
|
[float]
|
|
|
|
[[merging-conflicts]]
|
|
|
|
=== Conflicts between fields in different types
|
2014-10-01 09:13:38 -04:00
|
|
|
|
2015-08-12 15:21:37 -04:00
|
|
|
Fields in the same index with the same name in two different types must have
|
|
|
|
the same mapping, as they are backed by the same field internally. Trying to
|
|
|
|
<<updating-field-mappings,update a mapping parameter>> for a field which
|
|
|
|
exists in more than one type will throw an exception, unless you specify the
|
|
|
|
`update_all_types` parameter, in which case it will update that parameter
|
|
|
|
across all fields with the same name in the same index.
|
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
|
|
|
TIP: The only parameters which are exempt from this rule -- they can be set to
|
2016-04-29 10:42:03 -04:00
|
|
|
different values on each field -- can be found in <<field-conflicts>>.
|
2014-10-01 09:13:38 -04:00
|
|
|
|
2016-04-29 10:42:03 -04:00
|
|
|
For example, this fails:
|
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
|
|
|
[source,js]
|
|
|
|
-----------------------------------
|
|
|
|
PUT my_index
|
|
|
|
{
|
|
|
|
"mappings": {
|
|
|
|
"type_one": {
|
|
|
|
"properties": {
|
|
|
|
"text": { <1>
|
2016-03-18 12:01:27 -04:00
|
|
|
"type": "text",
|
2015-08-12 15:21:37 -04:00
|
|
|
"analyzer": "standard"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"type_two": {
|
|
|
|
"properties": {
|
|
|
|
"text": { <1>
|
2016-03-18 12:01:27 -04:00
|
|
|
"type": "text",
|
2015-08-12 15:21:37 -04:00
|
|
|
"analyzer": "standard"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
PUT my_index/_mapping/type_one <2>
|
|
|
|
{
|
|
|
|
"properties": {
|
|
|
|
"text": {
|
2016-03-18 12:01:27 -04:00
|
|
|
"type": "text",
|
2015-08-12 15:21:37 -04:00
|
|
|
"analyzer": "standard",
|
|
|
|
"search_analyzer": "whitespace"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-29 10:42:03 -04:00
|
|
|
-----------------------------------
|
2016-05-09 09:42:23 -04:00
|
|
|
// CONSOLE
|
2016-04-29 10:42:03 -04:00
|
|
|
// TEST[catch:request]
|
|
|
|
<1> Create an index with two types, both of which contain a `text` field which have the same mapping.
|
|
|
|
<2> Trying to update the `search_analyzer` just for `type_one` throws an exception like `"Merge failed with failures..."`.
|
|
|
|
|
|
|
|
But this then running this succeeds:
|
2014-10-01 09:13:38 -04:00
|
|
|
|
2016-04-29 10:42:03 -04:00
|
|
|
[source,js]
|
|
|
|
-----------------------------------
|
|
|
|
PUT my_index/_mapping/type_one?update_all_types <1>
|
2015-08-12 15:21:37 -04:00
|
|
|
{
|
|
|
|
"properties": {
|
|
|
|
"text": {
|
2016-03-18 12:01:27 -04:00
|
|
|
"type": "text",
|
2015-08-12 15:21:37 -04:00
|
|
|
"analyzer": "standard",
|
|
|
|
"search_analyzer": "whitespace"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-----------------------------------
|
2016-05-09 09:42:23 -04:00
|
|
|
// CONSOLE
|
2016-04-29 10:42:03 -04:00
|
|
|
// TEST[continued]
|
|
|
|
<1> Adding the `update_all_types` parameter updates the `text` field in `type_one` and `type_two`.
|