Elasticsearch of Mappings

Mapping (Mapping)

Mapping is used to define a document, and the fields it contains, is how to store and index the process. For example, using the mapping can be defined:

  • Which should be seen as a string field full-text index field;
  • Field which contains a number, date, or a geographic location;
  • The value of all the fields of whether the documents are indexed to the _allfield;
  • Date Format field value;
  • Custom rules control whether to dynamically add an index (Annex 1)

Mapping type (Mapping Type)

Each index has a mapping type determines how the document is indexed.

A mapping types are:

Meta-fields

  • Meta fields used to customize how to handle the associated metadata document. Element field includes _index, _type, _id, _source.

Fields or properties

  • A mapping of the associated attribute type contains a list of fields or documents.

Field data types

Each field has a data type:

  • Behave types include: text, keyword, date, long, double, boolean, ip;
  • Support type object json hierarchy or nested.
  • The particular type geo_point, geo_shape, completion.

For different purposes and index the same field in different ways it is very common. For example, a string field may be set to text object to achieve full-text index, or set keyword is used to sort or polymeric. Optionally a case where two or more, in the case of the word, a string field to be used standard analyzer, english analyzer, french analyzeraliquots tokenizer.

This is a multi-purpose field. Most data types support multi-parameter field by field.

Prevent the proliferation of mapping settings

Too many fields defined in an index is a map that could cause an explosion, which could lead to out of memory errors and difficult to restore the situation. This problem may be more common than expected. For example, consider the following case, each newly added documents have introduced a new field. In this set of dynamic mapping it is very common. Every document contains the new field will be added to the index of the final map. In the case of small data set and there is no problem, but if you set the mapping of sustained growth will create problems. The following settings allow you to limit the number of field mapping, either manually or automatically created, in order to prevent poor documentation led to a surge map:

index.mapping.total_fields.limit

The maximum number of index fields. The default value of 1000.

index.mapping.depth.limit

The maximum depth of field, used to measure the number of internal objects. For example, if all of the fields are defined in the same level as the root object, then the depth is 1. If you have an object mapping, then the depth is 2, and so on. The default value of 20.

index.mapping.nested_fields.limit

In an index nested maximum number of field defaults to 50. A nested index has 100 field documents actually indexed 101 documents, as each nested documents will be indexed as a separate hidden documents.

Dynamic mapping (Dynamic mapping)

Field mapping types and need not be defined before use. Thanks to Dynamic Mapping , the new field name is automatically added, and the index. The new fields can be added to both the top mapping types can be added to objectand nestedinside the field.

Explicit mapping (Explicit mappings)

Despite the dynamic mapping it is easy to learn in the beginning, but in case you know more about the data than guess Elasticsearch, specify your own display mapping is more appropriate.

Update existing field mapping

In addition to local records, field mapping already exists can not be updated . Change the mapping will mean the document already exists index is invalid. Instead, you should create a new index has the correct mapping, and data re-indexing (reindex) to the index. If you want to rename the field without changing its map, you can use the alias field implementation.

For example

When creating an index that is mapped can be specified as follows:

PUT my_index 
{
  "mappings": {
    "_doc": { 
      "properties": { 
        "title":    { "type": "text"  }, 
        "name":     { "type": "text"  }, 
        "age":      { "type": "integer" },  
        "created":  {
          "type":   "date", 
          "format": "strict_date_optional_time||epoch_millis"
        }
      }
    }
  }
}
curl -X PUT "localhost:9200/my_index" -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "_doc": { 
      "properties": { 
        "title":    { "type": "text"  }, 
        "name":     { "type": "text"  }, 
        "age":      { "type": "integer" },  
        "created":  {
          "type":   "date", 
          "format": "strict_date_optional_time||epoch_millis"
        }
      }
    }
  }
}
'

appendix

Annex 1

Dynamic map

One of the most important features characteristic Elasticsearch easy to use, allows you to quickly get your data into use. In order to index a document, you do not have to go to create the index, define the mapping type, then define the fields ---- index a document, and then indexing, mapping, field will be created automatically:

PUT data/_doc/1 
{ "count": 5 }
curl -X PUT "localhost:9200/data/_doc/1" -H 'Content-Type: application/json' -d'
{ "count": 5 }
'

Note: The above data is created index, mapping type _doc, and field count, the data type is long.

Automatic detection and add new fields called dynamic mapping. Dynamic mapping rules can be customized in the following ways, to meet specific purposes:

  1. Dynamic control field mapping rules :( dynamic field detection)
  2. Dynamic template :( configure a custom rule for the field mapping dynamically added)

Note: The index template in either dynamically created, or create a display, allows you to configure the default mapping settings, the new index aliases.
Translated from:

  1. https://www.elastic.co/guide/en/elasticsearch/reference/6.4/mapping.html
  2. https://www.elastic.co/guide/en/elasticsearch/reference/6.4/dynamic-mapping.html

Guess you like

Origin blog.csdn.net/qq_35958788/article/details/92801225