Elasticsearch 数据类型

摘要

Elasticsearch 支持大量的数据类型。
支持参数,会单独成章,可以查看,暂时未完成。

text datatype 文本数据类型

用于全文搜索的字段,例如电子邮件的正文或产品的描述。这些字段是可分析的,也就是说,它们通过分析器分析,以便 在被索引之前将字符串转换为单个术语的列表。通过分析过程,Elasticsearch 可以在每个全文字段中搜索单个单词。文本字段不用于排序,很少用于聚合。

接受参数: analyzer,boost,eager_global_ordinals,fielddata,fielddata_frequency_filter,fields,index,index_options,index_prefixes,index_phrases,norms,position_increment_gap,store,search_analyzer,search_quote_analyzer,similarity,term_vector,meta

keyword datatype 关键字数据类型

用于索引结构化内容(例如ID,电子邮件地址,主机名,状态代码,邮政编码或标签)的字段。它们通常用于过滤、排序、聚合。关键字字段只按照其确切值进行搜索。

接受参数
analyzer,boost,eager_global_ordinals,fielddata,fielddata_frequency_filter,fields,index,index_options,index_prefixes,index_phrases,norms,position_increment_gap,store,search_analyzer,search_quote_analyzer,similarity,term_vector,meta

Numeric 数字

整数类型,占用内存最小,有助于索引和搜索更加有效。但请注意,存储是根据实际值进行优化的,因此选择一种类型而不是另一种类型不会影响存储需求
对于浮点类型,使用缩放因子将浮点数存储为整数通常会更加有效,scaled_float类型会自动在后台执行此操作。这对于节省磁盘空间很有帮助,因为整数比浮点数更容易压缩。
支持类型,根据需要选择类型
long,integer,short,byte,double,float,half_float,scaled_float

接受参数
coerce,boost,doc_values,ignore_malformed,index,null_value,store,meta

Date 日期

支持类型
date

接受参数
boost,doc_values,format,locale,ignore_malformed,index,null_value,store,meta

请求示例

PUT my_index
{
  "mappings": {
    "properties": {
      "date": {
        "type": "date"
        /*可以指定日期格式*/
       /*, "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"*/ 
      }
    }
  }
}

PUT my_index/_doc/1
{ "date": "2015-01-01" } 

PUT my_index/_doc/2
{ "date": "2015-01-01T12:10:30Z" } 

PUT my_index/_doc/3
{ "date": 1420070400001 } 

GET my_index/_search
{
  "sort": { "date": "asc"} 
}

Date nanoseconds

该数据类型是该数据类型的补充date。但是,两者之间有重要区别。现有date数据类型以毫秒为单位存储日期。该date_nanos数据类型存储在纳秒的分辨率,这限制了它的范围内的日期从大约1970至2262年,为日期仍然作为从epoch长表示纳秒存储日期

支持类型
date_nanos

boolean 布尔类型

布尔字段接受JSON true和false值,但也可以接受解释为true或false的字符串:

支持类型
boolean

接受参数
boost,doc_values,index,null_value,store,meta

Binary 二进制

该binary类型接受二进制值作为 Base64编码的字符串。该字段默认情况下不存储,并且不可搜索

接受参数
doc_values,store

请求示例

PUT my_index
{
  "mappings": {
    "properties": {
      "name": {
        "type": "text"
      },
      "blob": {
        "type": "binary"
      }
    }
  }
}

PUT my_index/_doc/1
{
  "name": "Some binary blob",
  "blob": "U29tZSBiaW5hcnkgYmxvYg==" 
}

Range

支持类型
integer_range,float_range,long_range,double_range,date_range,ip_range,

接受参数
coerce,boost,index,store

请求示例

PUT range_index
{
  "settings": {
    "number_of_shards": 2
  },
  "mappings": {
    "properties": {
      "expected_attendees": {
        "type": "integer_range"
      },
      "time_frame": {
        "type": "date_range", 
        "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
      }
    }
  }
}

PUT range_index/_doc/1?refresh
{
  "expected_attendees" : { 
    "gte" : 10,
    "lte" : 20
  },
  "time_frame" : { 
    "gte" : "2015-10-31 12:00:00", 
    "lte" : "2015-11-01"
  }
}

Object datatype 对象数据类型

JSON文档本质上是分层的:文档可能包含内部对象,而内部对象又可能包含内部对象本身

接受参数
dynamicenabledproperties

Nested datatype 嵌套数据类型

nested类型是object数据类型的专用版本,它允许以可以彼此独立地查询对象的方式对对象数组进行索引。
当数据类型嵌套

详情请看

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