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

}

相关推荐
wuminyu2 小时前
JVM规范学习总结:解释器与JIT编译器如何处理JVM字节码
java·linux·c语言·jvm·c++
txxzjmzlh2 小时前
SpringBoot 配置⽂件
java·spring boot·spring
小徐不徐说2 小时前
序列化与反序列化:把 C++ 对象可靠地保存下来
开发语言·数据库·c++·php
ragnwang3 小时前
Notes: Python pybind11 import C++ module
开发语言·c++·python
Wang's Blog3 小时前
Java 项目实战: 交友项目 - 搜索附近的功能概述和分析
java·开发语言·交友
骑着蜗牛撵大象3273 小时前
大模型 Agent 的沙箱护栏:gVisor 隔离、出口白名单与审计闭环
java·开发语言·jvm·安全·agent沙箱·gvisor·microvm
独泪了无痕3 小时前
Hutool之LocalDateTimeUtil:让时间间隔操作如虎添翼
java
Dxy12393102164 小时前
JS DES 加密详解
开发语言·javascript·arcgis
充值内卷4 小时前
我给桌面加了个鱼缸:C++ 写后端,WebView2 里养一座 Three.js 小岛
开发语言·javascript·c++
云和数据.ChenGuang4 小时前
深入解析 Python 的 dir():从用法到 CPython 源码实现
开发语言·人工智能·python·langchain