elasticsearch入門使用 Mapping + field type字段類型


Elasticsearch Reference [6.2] ? Mapping
參考官方英文文檔 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
  6. 范圍類型
    integer_range, float_range, long_range, double_range, date_range
  7. Array數據類型(Array不需要定義特殊類型)

    [ "one", "two" ]
    [ 1, 2 ]
    [{ "name": "Mary", "age": 12 },{ "name": "John", "age": 10}]
  8. Object數據類型 (json嵌套)

    { 
      "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.2/mapping-params.html

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM