珠宝网站方案,中国网页设计师,静态网站如何添加关键词,企业邮箱收费吗mapping映射属性
mapping是对索引库中文档的约束
常见的mapping属性包括#xff1a;
type 字段数据类型#xff0c;常见的简单类型有#xff1a; 字符串#xff1a;text(可分词的文本) keyword(精确值#xff0c;例如#xff1a;品牌、国家#xff0c;ip地址) 数值
type 字段数据类型常见的简单类型有 字符串text(可分词的文本) keyword(精确值例如品牌、国家ip地址) 数值long integer short byte double float 布尔boolean 日期date 对象object例如下面name字段的值就是一个json对象。
index 是否创建索引默认为true,表示创建倒排索引会参与到搜索。false表示不会创建倒排索引不会参与搜索。
analyzer 使用哪种分词器跟上面type为text的字段结合使用。
properties该字段的子字段。例如下面指定name字段的子属性firstName和lastName。
es没有数组类型但是es中允许字段有多个值所以支持存储数组数据。只需要关注数组中元素的类型就可以了。 { age: 22, weight: 52.1, isMarried: false, info: 我是一个程序员很有才华的哟, email: aaaqq.com score: [99, 85, 77] name: { firstName: 云, lastName: 赵 } } 索引库的CRUD
1.创建索引库和mapping的DSL语句 # 创建索引库person并定义字段mapping PUT /person { mappings: { properties: { info: { type: text, analyzer: ik_smart }, email: { type: keyword, index: false }, name: { type: object, properties: { firstName: { type: keyword }, lastName: { type: keyword } } }, age: { type: integer }, weight: { type: float }, isMarried: { type: boolean }, score: { type: integer }, birthday: { type: date } } } } 执行结果 { acknowledged : true, shards_acknowledged : true, index : person } 2.查询索引库 GET /person 3.删除索引库 delete /person 4.修改索引库
在es中可以允许添加新字段只是禁止修改原字段。 PUT /person/_mapping { properties: { heigh:{ type: float } } } { acknowledged : true }