What is the Mapping
1.Mapping is similar to the definition of Schema in a database 1.Defines the name of the field in the index 2.Defines the data types of fields, such as strings, numbers, booleans 3.Field, related configuration of inverted index2.Mapping maps JSON documents into the flat format that Lucene needs3.A Mapping belongs to the Type of an index 1.Each document belongs to an index Type 2.A Type has a Mapping definition 3.7.0 From now on, you do not need to specify Type information in the Mapping definitionCopy the code
What is Dynamic Mapping
1.When a document is written, an index is automatically created if it does not exist2.The Dynamic Mapping mechanism eliminates the need to manually define Mappings. ES calculates automatic types based on the document information3.But sometimes the calculations are wrong, such as with geographical location4.When the type is not set correctly, some functions, such as the Range query, will not work properlyCopy the code
The data type of the field
1.A simple type 1. Text/Keyword
2. Date
3. Integer/Floating
4. Boolean
5. IPV4 & IPV6
2.The complex type 1.Object type 2.Nested object types3.Special type 1. geo_point & geo_shape / percolator
Copy the code
Automatic identification of types
Look at the Mapping
Run the following command in the development tool: GET /movies/_mapping The response is as follows: {"movies" : {
"mappings" : {
"properties" : {
"@version" : {
"type" : "text"."fields" : {
"keyword" : {
"type" : "keyword"."ignore_above" : 256}}},"genre" : {
"type" : "text"."fields" : {
"keyword" : {
"type" : "keyword"."ignore_above" : 256}}},"id" : {
"type" : "text"."fields" : {
"keyword" : {
"type" : "keyword"."ignore_above" : 256}}},"title" : {
"type" : "text"."fields" : {
"keyword" : {
"type" : "keyword"."ignore_above" : 256}}},"year" : {
"type" : "long"
}
}
}
}
}
Copy the code
Whether to change the field type of the Mapping
1.Newly added field 1.When Dynamic is set to true, the Mapping is updated as soon as documents with new fields are written 2.If Dynamic is set to false, the Mapping will not be updated and the new field data will not be indexed, but the information will appear in theScoure 3. Set "Dynamic" to "Stict", document writing fails 2. For existing fields, once data is written, the field definition cannot be changed. 1. Lucene implements a pending index, once generated, it cannot be changed. If you want to change the field type, you must Reindex the index API. If the data type of a field is changed, indexed entries cannot be searched. 2. But if it is a new field, there is no such effectCopy the code
How to display the definition of a Mapping
PUT movies
{
"mappings": {// define your mappings here}}Copy the code
Some suggestions for customizing Mapping
1.Refer to the API manual and write it by hand2.In order to reduce input workload and reduce error probability, the following steps can be followed: 1.Create a temporary Index and write some sample data 2.Get the dynamic Mapping definition for this temporary file by accessing the Mapping API 3.After modification, use this configuration to create your index 4.Drop temporary indexCopy the code
More content welcome to pay attention to my personal public number “Han Elder brother has words”, 100G artificial intelligence learning materials, a large number of back-end learning materials waiting for you to take.