021 elasticsearch索引管理

文章目录

概念 说明
索引库(indexes) 索引库包含一堆相关业务,结构相似的文档document数据,比如说建立一个商品product索引库,里面可能就存放了所有的商品数据。
类型(type) type是索引库中的一个逻辑数据分类,一个type下的document,都有相同的field,类似于数据库中的表。比如商品type,里面存放了所有的商品document数据。6.0版本以后一个index只能有1个type,6.0版本以前每个index里可以是一个或多个type。7.0以后,没有type这个概念了
文档(document) 文档是es中的存入索引库最小数据单元,一个document可以是一条客户数据,一条商品数据,一条订单数据,通常用JSON数据结构表示。document存在索引库下的type类型中
字段(field) Field是Elasticsearch的最小单位。一个document里面有多个field,每个field就是一个数据字段
映射配置(mappings) 对type文档结构的约束叫做映射(mapping),用来定义document的每个字段的约束。如:字段的数据类型、是否分词、是否索引、是否存储等特性。type是模拟mysql中的table概念。表是有结构的,也就是表中每个字段都有约束信息

索引的管理

bash 复制代码
http://localhost:9200/_all

1创建索引库

复制代码
方法:put
url:http://localhost:9200/{索引名称}

2删除索引

3设置mapping

就是索引中文档格式的定义

文档中包含的字段的名称、数据类型、是否索引、是否存储、是否分词

最好是先定义好mapping,然后再添加数据,不定义mapping也可以添加文档,es会根据Document格式推断出mapping的定义

创建索引库时定义mapping

方法:put

url: http://localhost:9200/{索引名称}

例如:http://localhost:9200/blog

请求体:

如果要进行分词处理必须使用text类型,keyword类型不分词

如果document中的内容在后续业务中有需要就要存储,否则就可以不存储。不存储也可以分词创建索引,不影响搜索

不分词也可以创建索引

json 复制代码
{
	"mappings":{
		"properties":{
			"id":{
				"type":"long"
			},
			"title":{
				"type":"text",
				"analyzer":"standard",
				"store":"true",
				"index":true
			},
			"mobile":{
				"type":"keyword",
				"store":"true",
				"index":true
			},
			"comment":{
				"type":"text",
				"analyzer":"standard",
				"store":"true",
				"index":true				
			}
		}
	}
}
先创建索引库然后设置mapping

方法:post

url:http://localhost:9200/{索引名称}/_mapping

请求体:

json 复制代码
{
		"properties":{
			"id":{
				"type":"long"
			},
			"title":{
				"type":"text",
				"analyzer":"standard",
				"store":"true",
				"index":true
			},
			"mobile":{
				"type":"keyword",
				"store":"true",
				"index":true
			},
			"comment":{
				"type":"text",
				"analyzer":"standard",
				"store":"true",
				"index":true				
			}
		}
}

4设置settings

创建索引库时设置settings

方法:put

url: http://localhost:9200/{索引名称}

例如:http://localhost:9200/blog

请求体:

json 复制代码
{
	"settings":{
		"number_of_shards": "5",
		"number_of_replicas": "1"
	}
}
创建索引之后修改settings

分片数量在创建索引库之后就不能再修改了

可以修改副本的数量

方法:put

url: http://localhost:9200/{索引名称}/_settings

例如:http://localhost:9200/blog/_settings

请求体:

json 复制代码
{
	"number_of_replicas": "1"
}
相关推荐
夜斗小神社3 小时前
【黑马SpringCloud微服务开发与实战】(九)elasticsearch基础
elasticsearch·spring cloud·微服务
Elastic 中国社区官方博客11 小时前
用于 UBI 的 Elasticsearch 插件:从搜索查询中分析用户行为
大数据·数据库·elasticsearch·搜索引擎·全文检索
wdfk_prog11 小时前
实战指南:如何将Git仓库中的特定文件夹及其历史完整迁移到另一个仓库
大数据·linux·运维·笔记·git·学习·elasticsearch
乌萨奇也要立志学C++18 小时前
【Linux】linux基础开发工具(三) 版本控制器Git、调试器 - gdb/cgdb使用、一些实用的调试技巧
linux·git·elasticsearch
阿乾之铭2 天前
Elasticsearch
elasticsearch·搜索引擎
程序员编程指南2 天前
Qt 开发 IDE 插件开发指南
c语言·c++·ide·qt·elasticsearch
谷新龙0013 天前
Elasticsearch服务器开发(第2版) - 读书笔记 第二章 索引
服务器·elasticsearch
所念皆为东辞3 天前
elk部署加日志收集
linux·elk·elasticsearch·centos
可曾去过倒悬山3 天前
Mac上优雅简单地使用Git:从入门到高效工作流
git·elasticsearch·macos
Hello.Reader3 天前
用 Go Typed Client 快速上手 Elasticsearch —— 从建索引到聚合的完整实战
elasticsearch·golang·jenkins