不为失败找理由,要为成功找方法。

Elasticsearch mapping 配置个人解读

Elasticsearch | 作者 夏李俊 | 发布于2018年02月09日 | | 阅读数:5301


配置详解
文件中"mapping":{}中的内容,即为创建索引的mappingsource 如:
"mappings": {
"_default_" : { //@1
"_all" : {"enabled" : true}, //@2
"properties" : { //@3
"tableType" : {"type" : "string", "index" : "no", "include_in_all" : false, "store": true}, //@4
"caption" : {"type" : "string", "index" : "no", "include_in_all" : false, "store": true},
"code" : {"type" : "string", "index" : "no", "include_in_all" : false, "store": true},
"description" : {"type" : "string", "index" : "no", "include_in_all" : false, "store": true},
"perm" : {"type" : "string", "index" : "not_analyzed", "include_in_all" : false}
}
},
"ec02_goodsinfo" : { //@5
"_all" : {"enabled" : true}, //@6
"properties" : { //@7
"tableType" : {"type" : "string", "index" : "no", "include_in_all" : false, "store": true},
"caption" : {"type" : "string", "index" : "no", "include_in_all" : false, "store": true},
"code" : {"type" : "string", "index" : "no", "include_in_all" : false, "store": true},
"description" : {"type" : "string", "index" : "no", "include_in_all" : false, "store": true},
"perm" : {"type" : "string", "index" : "not_analyzed", "include_in_all" : false},
"bill":{ //@8
properties" : {
"CreateYear" : {"type" : "string", "index" : "not_analyzed", "include_in_all" : true} //@9
}
}
}
}
}

  • @1 _default_所有单据默认的创建索引的配置
  • @2 _all{} 每个单据下所有的字段配置,"enabled" : true 所有字段创建索引,false 所有字段禁止创建索引,[*注意]除非properties指定的字段,默认字段类型将自动匹配
  • @3 properties {},每个单据下字段或者properties的指定配置
  • @4 properties {}中指定了属性(properties):"tableType"的检索配置,type:string > 类型字符串,include_in_all:false > 改字段或者属性不包含在单据的所有字段中,"store": true > 储存在数据库中
  • @5 ec02_goodsinfo 表示对单据 "ec02_goodsinfo" 的特定检索配置
  • @6 _all{} 只对"ec02_goodsinfo"单据下所有的字段配置
  • @7 properties {},只对"ec02_goodsinfo"单据下字段或者properties的指定配置
  • [*注意]@8,@9 bill在单据中额字段都会包括一层bill,所以如果要对单据中某个字段指定需要套一层bill{}

-----------------------------------------------------------------------------------------------------------------------------------------
属性解说
版本5.X以前
  • index 可选值为analyzed(默认)和not_analyzed,如果是字段是字符串类型的,则可以是not_analyzed
  • store 可选值为yes或no,指定该字段的原始值是否被写入索引中,默认为no,即结果中不能返回该字段。
  • boost默认为1,定义了文档中该字段的重要性,越高越重要
  • null_value 如果一个字段为null值(空数组或者数组都是null值)的话不会被索引及搜索到,null_value参数可以显示替代null values为指定值,这样使得字段可以被搜索到。
  • include_in_all 指定该字段是否应该包括在_all字段里头,默认情况下都会包含。
  • type 可以指定String,long,int,doulbe,floot,boolean,等

版本5.X以后
  • 原本type string,其index 可选值为analyzed(默认)和not_analyzed,现在直接拆违type text( index analyzed),type keyword(index not_analyzed)
  • store 可选值为enable或false,指定该字段的原始值是否被写入索引中,默认为enable,即结果中不能返回该字段。
  • index 表示是否用于检索默认enable,可选false

-------------------------------------------------------------------------------------------------------------------------------
字段的数据类型
  • 简单类型string(指定分词器)
  • date(默认使用UTC保持,也可以使用format指定格式)
  • 数值类型(byte,short,integer,long,float,double)
  • boolean
  • binary(存储在索引中的二进制数据的base64表示,比如图像,只存储不索引)
  • ip(以数字形式简化IPV4地址的使用,可以被索引、排序并使用IP值做范围查询)注意string是5.x以前的,5.x之后被分裂为text,keyword


有层级结构的类型,比如object 或者 nested.
特殊类型
  • geo_point
  • geo_shape
  • completion

 

[尊重社区原创,转载请保留或注明出处]
本文地址:http://elasticsearch.cn/article/492


0 个评论

要回复文章请先登录注册