上QQ阅读APP看书,第一时间看更新
How it works...
The first command line creates an index where we'll configure the type/mapping and insert the documents.
The second command inserts a document in the index (we'll see the index's creation in the Creating an index recipe in Chapter 3, Basic Operations, and record indexing in the Indexing a document recipe in Chapter 3, Basic Operations).
During the document index phase, Elasticsearch internally checks if the _doc type exists, otherwise it creates one dynamically.
Elasticsearch reads all the default properties for the field of the mapping and starts to process them as follows:
- If the field is already present in the mapping and the value of the field is valid (it matches the correct type), Elasticsearch does not need to change the current mappings.
- If the field is already present in the mapping but the value of the field is of a different type, it tries to upgrade the field type (that is, from integer to long). If the types are not compatible, it throws an exception and the index process fails.
- If the field is not present, it tries to auto detect the type of field. It updates the mappings with a new field mapping.