Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Dynamic Mapping and common field types
What is Mapping
- Similar mapping database schema definition, role is as follows:
- Name defined index fields
- Field data type definition, such as strings, numbers, Boolean ...
- Field, inverted index configuration, Analyzed or Not Analyzed, Analyzer
- JSON document mapping will be mapped into the flat form required Lucene
- A mapping belonging to an index of type
- Each document belongs to a Type
- Mapping a Type has a defined
- 7.0, do not need to specify the type of information in the mapping definition
Field data types
- Simple type
- Text/Keyword
- Date
- Integer/Floating
- Boolean
- ipv4 & ipv6
- Complex types - objects and nested objects
- Object Type / nested type
- Special type
- geo_point & geo_shape & percolator
What is Dynamic Mapping
- In written documents, when, if the index does not exist, it will automatically create an index
- Dynamic Mapping mechanism, so that we do not need to manually define Mappings. Elasticsearch automatically according to the document information, calculate the type of the field
- But sometimes the wrong projections, such as geographic location information
- When the type If not, it will cause some features not work properly, for example: Range query
查看Mapping
- 1
Automatic identification of the type
JSON type | Elasticsearch type |
---|---|
String | 1, matching log format, provided Date 2, arranged to float or configure the digital long, this option is off by default 3, set to Text, and increase the keyword subfields |
Boolean value | boolean |
Float | float |
Integer | long |
Objects | Object |
Array | Determined by the type of the first non-null value |
Null | ignore |
Mapping can change field type
- In both cases
- New field
- Dynamic When set to true, if there is a document written in the new field, Mapping also be updated
- When Dynamic set to false, Mapping will not be updated, new data fields can not be indexed, but the information will appear in the _source
- Dynamic set to Strict, file write failure
- Existing field, once the data has been written, it is no longer modify the field definition support
- Lucene inverted index to achieve, once generated, can not be modified
- If you want to change the field type, you must Reindex API, rebuild the index
- New field
- the reason
- If you modify the data type of the field, will result has been indexed belongs to can not be searched
- But if it is to add a new field, there would be no such effects
Control Dynamic Mappings
air | “true” | “false” | “strict” |
---|---|---|---|
Documents can be indexed | YES | YES | NO |
Fields indexable | YES | NO | NO |
Mapping was updated | YES | NO | NO |
PUT movies
{
"mappings":{
"_doc":{
"dynamic":"false"
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- When dynamic time is set to false, the presence of additional fields into the data, the data may be indexed, but the new field is discarded
- When set to Strict mode when data is written directly Error