ElasticSearch-Mapping field字段type類型

參考官方英文文檔:https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html

Mapping是定義文檔及其包含的字段如何存儲和編制索引的過程,每個索引都有一個映射類型,用於確定文檔將如何編制索引。

Meta-fields
包括文檔的_index,_type,_id和_source字段

es字段數據類型:
https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html

1.字符串類型
textkeyword
2.數值類型
long、integer、short、byte、double、float、half_float、scaled_float
3.日期類型
date
4.布爾值類型
boolean
5.二進制類型
binary(接受二進制值作爲Base64編碼字符串。 該字段默認情況下不存儲,不可搜索)
6.範圍類型
integer_range、float_range、long_range、double_range、date_range
7.Array數據類型Array不需要定義特殊類型
在 Elasticsearch 中,沒有特定的 array 類型。默認情況下,任何字段都可以包含0個或者更多值,但是,所有 array 中的值必須具有相同的數據類型,例如:
字符串數組:[“one”, “two”]
整數數組:[1,2]
數組的數組:[1, [2, 3]],等價於[1,2,3]
對象數組:[ { “name”: “Mary”, “age”: 12 }, { “name”: “John”, “age”: 10 }]

當自動添加一個字段,array 的第一個值決定了字段的類型。所有接下來的值必須使用相同的數據類型或者必須至少能將他們轉換爲與它相同的類型
數組不支持混合的數據類型:[10, “some string”]
數組可以包含null值,這些值可以由配置的null_value替換或完全跳過。一個空的array[]被視爲不存在的字段-無值的字段。

文檔中使用 array 類型不需要提前做任何配置,天生就支持。

PUT my_index/my_type/1
{
  "message": "some arrays in this document...",
  "tags":  [ "elasticsearch", "wow" ],
  "lists": [
    {
      "name": "prog_list",
      "description": "programming list"
    },
    {
      "name": "cool_list",
      "description": "cool stuff list"
    }
  ]
}

8.Object數據類型 (json嵌套)
object for single JSON objects

{ 
  "region": "US",
  "manager": { 
    "age":     30,
    "name": { 
      "first": "John",
      "last":  "Smith"
    }
  }
}

9.地理數據類型
Geo-pointGeo-Shape(比較複雜,參考官網文檔,一般用Geo-point就可以了)
10.特殊數據類型
ip(IPv4 and IPv6 addresses)
completion(自動完成/搜索)
token_count(數值類型,分析字符串,索引的數量)
murmur3(索引時計算字段值的散列並將它們存儲在索引中的功能。在高基數和大字符串字段上運行基數聚合時有很大幫助)
join(同一索引的文檔中創建父/子關係)

以下是常用的參數類型定義&賦值demo

類型 參數定義 賦值
text “name”:{“type”:“text”} “name”: “zhangsan”
keyword “tags”:{“type”:“keyword”} “tags”: “abc”
date “date”:{“type”: “date”} “date”:“2015-01-01T12:10:30Z”
long “age”:{“type”:“long”} “age” :28
double “score”:{“type”:“double”} “score”:98.8
boolean “isgirl”: { “type”: “boolean” } “isgirl” :true
ip “ip_addr”:{“type”:“ip”} “ip_addr”: “192.168.1.1”
geo_point “location”: {“type”:“geo_point”} “location”:{“lat”:40.12,“lon”:-71.34}

Mapping parameters
https://www.elastic.co/guide/en/elasticsearch/reference/6.6/mapping-params.html

analyzer
normalizer
boost
coerce
copy_to
doc_values
dynamic
enabled
fielddata
eager_global_ordinals
format
ignore_above
ignore_malformed
index_options
index_phrases
index_prefixes
index
fields
norms
null_value
position_increment_gap
properties
search_analyzer
similarity
store
term_vector

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章