您的位置:首页 > 移动开发

全文检索(elasticsearch) 索引mapping的配置指南

2018-02-09 14:18 288 查看

配置详解

文件中"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{}

属性解说

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

字段的数据类型

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

有层级结构的类型,比如object 或者 nested.
特殊类型,比如geo_point, geo_shape, or completion.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: