7.索引库操作

mapping映射属性

mapping是对索引库中文档的约束

常见的mapping属性包括:

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": "aaa@qq.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

}

相关推荐
油丶酸萝卜别吃4 小时前
utils.js 说明文档
开发语言·javascript·ecmascript
rannn_1116 小时前
【力扣hot100】链表专题|160、206、234、141、142
java·算法·leetcode·链表·面试·开发
leisoo80977 小时前
100GBA股股票数据怎么存ClickHouseRedisMySQLJSON完整对比
大数据·linux·服务器·开发语言·python
不会代码的小猴7 小时前
21. 泛型编程上
开发语言·c++·笔记·算法
IKUN家族8 小时前
Spring IoC&DI
java·spring·rpc
一只旭宝8 小时前
细讲C加加【9】C++ std::function与std::bind详解|仿函数、绑定器、类成员绑定、占位符、成员偏移指针
开发语言·c++·算法
山荷枝9 小时前
03-框架--Spring
java·后端·spring
ChaHae-In10 小时前
SpringBoot统一功能处理
java·spring boot·后端
coder!mq10 小时前
说几个常见的语法糖?
java·开发语言·算法
gugucoding10 小时前
38. 【Java】Stream API(下):高级操作与性能
java·开发语言