There is a very important feature in ES-- dynamic mapping , that is, you do not need to create indexes, types, and so on before indexing a document, and the indexes, types, and mappings are created automatically at the same time.
So what is mapping? Mapping is what describes the types of fields, how to analyze them, how to index them, and so on.
This article focuses on the automatic detection of mappings in ES.
More content reference: Elastisearch Knowledge Summary
Field Auto-detection
When a field first appears, if no mappings have been previously defined, ES automatically detects the types that it might satisfy, and then creates the corresponding mappings.
JSON data |
Data types in ES |
null
|
Fields are not added |
true Orfalse
|
Boolean |
Floating point number |
Double |
Integer |
Long |
Object |
Object |
Array |
Dependent on the first non-null value |
String |
If date detection is passed, the date If numeric detection is passed, number |
Above is the result of type automatic detection, in addition to the basic types listed above, other advanced types such as GEO,IP need to be manually specified.
Date Automatic detection
Date automatic detection, that is, Date_detection is on by default, so as long as the default date format, you can automatically create a date type
The format of the date is:
" Strict_date_optional_time ","yyyy/mm/dd HH:mm:ss z| | YYYY/MM/DD Z"]
For example:
$ curl-xput localhost:9200/test/test/1-D'{"Create": "2015/11/11"}'{"_index":"Test","_type":"Test","_id":"1","_version":1,"created":true}$ Curl-xget localhost:9200/test/_mapping?pretty{"Test" : { "Mappings" : { "Test" : { "Properties" : { "Create" : { "type":"Date", "format":"YYYY/MM/DD hh:mm:ss| | YYYY/MM/DD" } } } } }}
You can modify the dynamic_date_formats
date format by modifying:
PUT my_index{ "mappings": { "My_type": { "dynamic_date_formats": ["mm/dd/yyyy"]} } }put my_index/my_type/1{"create_date":"09/25/ "}
Digital Automatic Detection
Digital Auto-detect, that is, Numeric_detection is off by default. So you need to open it manually:
PUT my_index{"mappings": {"my_type": {" numeric_detection ":True}}}
When the index operation is performed, the float is automatically created
The long type is the same:
Elasticsearch Dynamic Mapping--automatic detection