| Core Type | String Type | String, Text, Keyword |
| Integer Type | Integer, Long Integer, Short Integer, Byte Integer |
| floating point type | double, float, half _ float, scaled _ float |
| Logical type | Boolean type |
Date Type | Date |
| Scope Type | Scope |
Binary Type | Binary |
| Composite Type | Array Type | Array |
| Object Type | Object |
| Nested Type | Nested |
| Geographical type | Geographical coordinate type | Geographical point |
Geographic map | geographic shape |
| Special type | IP type | ip |
| Scope Type | Complete |
| Token Count Type | Token Count |
| Attachment type | Attachment |
Select Type | Filter |
(1) string
String type is widely used in old ElasticSearch. Starting from ElasticSearch 5.x, string is no longer supported, and text and keyword types are replaced.
(2) Text
When searching for fields in the full text, such as email content and product description, you should use the text type. After setting the text type, the content of the field will be analyzed, and before generating the inverted index, the analyzer will divide the string into word items. Fields of text type are not used for sorting and are rarely used for aggregation.
(3) Keywords
Keyword types are suitable for indexing structured fields, such as e-mail address, host name, status code and label. If you need to filter (for example, find published articles with status attribute in published blogs), sort and aggregate the fields. Fields of keyword type can only be searched by exact values.
Under the condition of meeting the requirements, choose the smallest possible data type. For example, the maximum value of a field will not exceed 100, and the byte type can be selected. Up to now, the oldest age recorded by Guinness is 134 years old. For the age field, short is enough. The shorter the field length, the higher the efficiency of indexing and searching.
For float, half_float and scaled_float, -0.0 and +0.0 are different values. Using $ term query to find -0.0 will not match +0.0. Similarly, in the range query, the upper boundary is -0.0 and the lower boundary is +0.0, which will not match -0.0.
Take scaled_float as an example, the price only needs to be accurate to the minute, the field scaling factor for the price of 57.34 is 100, and it is 5734 when stored.
Scaled_float floating-point type with scaling factor is preferred.
The timing system we humans use is quite complicated: seconds are basic UNIX, 60 seconds are 1 minute, 60 minutes are 1 hour, and 24 hours are a day ... If the computer uses the same way to time, it will obviously use multiple variables to store the year, month, day, hour and minute respectively, and carry out carry-over operations constantly, and also deal with accidental leap years.
The date type can be expressed in the following format:
(1) date format string, such as "2018-013" or "2018-0/-kloc-0/3/kloc"
(The number of milliseconds since the birth of UNIX (epoch means UTC time1970 65438+1October 1: 00: 00).
(3) The number of seconds since the era of 3 integers.
ElasticSearch internally converts date data into UTC and stores it as a long integer since the era.
Example: Date Format Data
(1) Create an index
(2) Writing documents
(3) Batch query
Logical types (Boolean types) can accept true/false/true/false values.
(1) Please delete the index before creating it.
(2) Add a document
(3) Check the document
Binary field refers to the binary data stored in the index represented by base64, which can be used to store binary data, such as images. By default, this type of field only stores non-indexes. Binary types only support the index_name attribute.
In ElasticSearch, there is no special array data type, but by default, any field can contain 0 or more values, which means that each field is array type by default, but the data type of each element value of array type must be the same. In ElasticSearch, arrays are out of the box and can be used directly without any configuration.
In the same array, the data types of array elements are the same. ElasticSearch does not support elements with multiple data types: [10, "some string"]. Commonly used array types are:
(1) character array: ["one ","two"]
(2) integer array: productid:[ 1, 2]
(3) Object (document) array: User: [{Name: Mary, Age: 12}, {Name: John, Age: 10}], and the object array is expanded in ElasticSearch.
JSON is hierarchical in nature, and documents contain nested objects.
The above document is a JSON as a whole, and JSON contains an employee, and employee also contains a fullname.
The ip type field is used to store the address of IPv4 or IPv6.
(1) Create an index
(2) Query field