- Elasticsearch Guide: other versions:
- Getting Started
- Setup
- Breaking changes
- Breaking changes in 2.0
- Removed features
- Network changes
- Multiple
path.data
striping - Mapping changes
- CRUD and routing changes
- Query DSL changes
- Search changes
- Aggregation changes
- Parent/Child changes
- Scripting changes
- Index API changes
- Snapshot and Restore changes
- Plugin and packaging changes
- Setting changes
- Stats, info, and
cat
changes - Java API changes
- Breaking changes in 2.0
- API Conventions
- Document APIs
- Search APIs
- Aggregations
- Metrics Aggregations
- Bucket Aggregations
- Children Aggregation
- Date Histogram Aggregation
- Date Range Aggregation
- Filter Aggregation
- Filters Aggregation
- Geo Distance Aggregation
- GeoHash grid Aggregation
- Global Aggregation
- Histogram Aggregation
- IPv4 Range Aggregation
- Missing Aggregation
- Nested Aggregation
- Range Aggregation
- Reverse nested Aggregation
- Sampler Aggregation
- Significant Terms Aggregation
- Terms Aggregation
- Pipeline Aggregations
- Caching heavy aggregations
- Returning only aggregation results
- Aggregation Metadata
- Indices APIs
- Create Index
- Delete Index
- Get Index
- Indices Exists
- Open / Close Index API
- Put Mapping
- Get Mapping
- Get Field Mapping
- Types Exists
- Index Aliases
- Update Indices Settings
- Get Settings
- Analyze
- Index Templates
- Warmers
- Shadow replica indices
- Indices Stats
- Indices Segments
- Indices Recovery
- Indices Shard Stores
- Clear Cache
- Flush
- Refresh
- Optimize
- Upgrade
- cat APIs
- Cluster APIs
- Query DSL
- Mapping
- Field datatypes
- Meta-Fields
- Mapping parameters
analyzer
boost
coerce
copy_to
doc_values
dynamic
enabled
fielddata
format
geohash
geohash_precision
geohash_prefix
ignore_above
ignore_malformed
include_in_all
index
index_options
lat_lon
fields
norms
null_value
position_increment_gap
precision_step
properties
search_analyzer
similarity
store
term_vector
- Dynamic Mapping
- Transform
- Analysis
- Analyzers
- Tokenizers
- Token Filters
- Standard Token Filter
- ASCII Folding Token Filter
- Length Token Filter
- Lowercase Token Filter
- Uppercase Token Filter
- NGram Token Filter
- Edge NGram Token Filter
- Porter Stem Token Filter
- Shingle Token Filter
- Stop Token Filter
- Word Delimiter Token Filter
- Stemmer Token Filter
- Stemmer Override Token Filter
- Keyword Marker Token Filter
- Keyword Repeat Token Filter
- KStem Token Filter
- Snowball Token Filter
- Phonetic Token Filter
- Synonym Token Filter
- Compound Word Token Filter
- Reverse Token Filter
- Elision Token Filter
- Truncate Token Filter
- Unique Token Filter
- Pattern Capture Token Filter
- Pattern Replace Token Filter
- Trim Token Filter
- Limit Token Count Token Filter
- Hunspell Token Filter
- Common Grams Token Filter
- Normalization Token Filter
- CJK Width Token Filter
- CJK Bigram Token Filter
- Delimited Payload Token Filter
- Keep Words Token Filter
- Keep Types Token Filter
- Classic Token Filter
- Apostrophe Token Filter
- Character Filters
- ICU Analysis Plugin
- Modules
- Index Modules
- Testing
- Glossary of terms
- Release Notes
WARNING: Version 2.0 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Put Mapping
editPut Mapping
editThe PUT mapping API allows you to add a new type to an existing index, or new fields to an existing type:
PUT twitter { "mappings": { "tweet": { "properties": { "message": { "type": "string" } } } } } PUT twitter/_mapping/user { "properties": { "name": { "type": "string" } } } PUT twitter/_mapping/tweet { "properties": { "user_name": { "type": "string" } } }
Creates an index called |
|
Uses the PUT mapping API to add a new mapping type called |
|
Uses the PUT mapping API to add a new field called |
More information on how to define type mappings can be found in the mapping section.
Multi-index
editThe PUT mapping API can be applied to multiple indices with a single request. It has the following format:
PUT /{index}/_mapping/{type} { body }
-
{index}
accepts multiple index names and wildcards. -
{type}
is the name of the type to update. -
{body}
contains the mapping changes that should be applied.
Updating field mappings
editIn 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 datatype fields. - new multi-fields can be added to existing fields.
-
doc_values
can be disabled, but not enabled. -
the
ignore_above
parameter can be updated.
For example:
PUT my_index { "mappings": { "user": { "properties": { "name": { "properties": { "first": { "type": "string" } } }, "user_id": { "type": "string", "index": "not_analyzed" } } } } } PUT my_index/_mapping/user { "properties": { "name": { "properties": { "last": { "type": "string" } } }, "user_id": { "type": "string", "index": "not_analyzed", "ignore_above": 100 } } }
Create an index with a |
|
Add a |
|
Update the |
Each mapping parameter specifies whether or not its setting can be updated on an existing field.
Conflicts between fields in different types
editFields 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
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.
The only parameters which are exempt from this rule — they can be set to different values on each field — can be found in Fields are shared across mapping types.
For example:
PUT my_index { "mappings": { "type_one": { "properties": { "text": { "type": "string", "analyzer": "standard" } } }, "type_two": { "properties": { "text": { "type": "string", "analyzer": "standard" } } } } } PUT my_index/_mapping/type_one { "properties": { "text": { "type": "string", "analyzer": "standard", "search_analyzer": "whitespace" } } } PUT my_index/_mapping/type_one?update_all_types { "properties": { "text": { "type": "string", "analyzer": "standard", "search_analyzer": "whitespace" } } }