Continue from section 17
3、Mapping
1), field type
-
Core type
- String
text
,keyword
- Digital type (Numeric)
long
,integer
,short
,byte
,double
,float
,half_float
,scaled_float
- Date type (Date)
date
- Boolean
boolean
- Binary type
binary
- String
-
Compound type
- Array type (Array)
Array
support is not for specific data types - Object type (Object)
object
An object used for a single JSON object - Nested type (Nested)
nested
for arrays of JSON objects
- Array type (Array)
-
Geographical type (Geo)
- Geographical coordinates (Geo-point)
geo_point
latitude/longitude coordinates - Geo-shape is
geo_shape
used for complex shapes such as polygons
- Geographical coordinates (Geo-point)
-
Specific type
- IP type (IP) is
ip
used to describe IPv4 and IPv6 addresses - Completion type (Completion)
completion
provides automatic completion prompt - Token count type is
token_count
used to count the number of entries in a string - Accessory Type (attachment)
Reference mapper-attachments plugin supports attachments such as Microsoft Office format, open document format, ePub, HTML and other indexattachment
data type. - The extraction type (Percolator)
acceptsquery-dsl
queries from a domain-specific language ( )
- IP type (IP) is
For more field types, please refer to the official ES document: reference document-mapping-types
2), mapping
Mapping (mapping)
Mapping 是用来定义一个文档(document),以及它所包含的属性(field)是如何存储和索引的
. For example, use mapping to define:
-
Which string attributes should be considered as full text fields
-
Which attributes contain numbers, dates or geographic locations
-
Whether all attributes in the document can be indexed (_all configuration)
-
Date format
-
Custom mapping rules to perform dynamic addition of attributes
-
View mapping information:
GET bank/_mapping
-
Modify the mapping information:
- Create index
PUT /my-index
{
"mappings": {
//映射规则
"properties": {
"age": {
"type": "integer" },
"email": {
"type": "keyword" },//keyword不会进行全文检索
"name": {
"type": "text" }//text保存的时候进行分词,搜索的时候进行全文检索
}
}
}
ES automatically guessed the mapping type:
JSON type | Domain type |
---|---|
Boolean: true, false | boolean |
Integer: 123 | long |
Floating point number: 1.23 | double |
String, valid date 2020-02-02 | date |
String, foo bar | string |
Objects, also known as hashes, store object types | object |
reference:
Getting started with the full-text search engine Elasticsearch