PUT my_index { // 建立 my_index索引 "mappings": { "user": { // 建立名稱爲user的type "_all": { "enabled": false }, //Disable the _all meta field for the user mapping type "properties": { "title": { "type": "string" }, "name": { "type": "string" }, "age": { "type": "integer" } } }, "blogpost": { "properties": { "title": { "type": "string" }, "body": { "type": "string" }, "user_id": { "type": "string", "index": "not_analyzed" }, "created": { "type": "date", "format": "strict_date_optional_time||epoch_millis" } } } }}
type: 字段的數據類型,例如 string 和 datehtml
a simple type like string
, date
, long
, double
, boolean
or ip
.git
a type which supports the hierarchical nature of JSON such as object
or nested
.github
or a specialised type like geo_point
, geo_shape
, or completion
.app
index: 字段是否應當被當成全文來搜索(analyzed),或被當成一個準確的值(not_analyzed),仍是徹底不可被搜索(no)elasticsearch
analyzer: 肯定在索引和或搜索時全文字段使用的分析器。ide
Elasticsearch supports a number of different datatypes for the fields in a document:post
string
spa
long
, integer
, short
, byte
, double
, float
date
boolean
binary
Array support does not require a dedicated type
object
for single JSON objects
nested
for arrays of JSON objects
geo_point
for lat/lon points
geo_shape
for complex shapes like polygons
ip
for IPv4 addresses
completion
to provide auto-complete suggestions
token_count
to count the number of tokens in a string
murmur3
to compute hashes of values at index-time and store them in the index
Attachment datatype
See the mapper-attachments
plugin which supports indexing attachments
like Microsoft Office formats, Open Document formats, ePub, HTML, etc. into an attachment
datatype.
It is often useful to index the same field in different ways for different purposes. For instance, a string
field could be indexed as an analyzed
field for full-text search, and as a not_analyzed
field for sorting or aggregations. Alternatively, you could index a string field with the standard
analyzer, the english
analyzer, and the french
analyzer.