Elasticsearch Document & Type & Index

本文涉及的产品
Elasticsearch Serverless通用抵扣包,测试体验金 200元
简介: 要了解Eleasticsearch,首先就要从基本的对象进行了解,这一篇是介绍什么是文档(Document),什么是类型(Document Type),什么是索引(Index),如何去创建和使用。

> 要了解Eleasticsearch,首先就要从基本的对象进行了解,这一篇是介绍什么是文档(Document),什么是类型(Document Type),什么是索引(Index),如何去创建和使用。


#### 文档(Document)

文档是 Elasticsearch 中可被搜索的最小单位,文档由多个字段的值组成,通过序列化 JSON 格式保存在Elasticsearch中,每一个文档都有唯一的ID。例如个人的简历、歌曲的详情等等都可以存储在文档中。


##### 文档元数据

用于标注文档的相关信息

_index :文档所属的索引名

_type :文档所属的类型名

_id :文档唯一ID

_source:文档的原始 JSON 数据

_version:文档的版本信息

_score:相关性打分


##### 文档字段的类型

基础类型:

字符串 String,String还包含 text(可被索引) 和 keywork(不分词不支持索引)

数值  包含Byte,Short,Integer,Long,Float,Double

数组类型 包含字符串和数值及对象型数组

地址位置类型 包含单一经纬度坐标 Geo-point 及区域性经纬度坐标 Geo-Shape

特殊类型包 含 IPv4,IPv6地址等类型


#### 类型(Document Type)

在 Elasticsearch 7.0 之前,一个 Index 可以创建多个 Document Type,但在 7.0 开始及之后,一个Index 只能对应一个 Document Type,且默认是 _doc 。


#### 索引(Index)

索引是一组相同类型的文档组合,例如歌曲索引中包含了粤语类型的歌曲文档,通过这个索引就可以找到所以粤语类型的歌曲。



#### REST API 操作

image.jpeg

索引的创建

PUTmateriel{
"settings" : {
"number_of_shards" : 3,
"number_of_replicas": 1  },
"mappings" : {
"properties" : {
"materiel" : { "type" : "text" },
"description" : { "type" : "text" }
    }
  }
}

往索引中写入文档

POSTmateriel/_doc/{
"materiel" : "10010001",
"description" : "橙汁"}


相关实践学习
以电商场景为例搭建AI语义搜索应用
本实验旨在通过阿里云Elasticsearch结合阿里云搜索开发工作台AI模型服务,构建一个高效、精准的语义搜索系统,模拟电商场景,深入理解AI搜索技术原理并掌握其实现过程。
ElasticSearch 最新快速入门教程
本课程由千锋教育提供。全文搜索的需求非常大。而开源的解决办法Elasricsearch(Elastic)就是一个非常好的工具。目前是全文搜索引擎的首选。本系列教程由浅入深讲解了在CentOS7系统下如何搭建ElasticSearch,如何使用Kibana实现各种方式的搜索并详细分析了搜索的原理,最后讲解了在Java应用中如何集成ElasticSearch并实现搜索。  
目录
相关文章
|
存储 API 数据库
检索服务elasticsearch索引(Index)
【8月更文挑战第23天】
636 6
|
存储
Elasticsearch exception [type=cluster_block_exception, reason=blocked by: [FORBIDDEN/12/index r【已解决】
Elasticsearch exception [type=cluster_block_exception, reason=blocked by: [FORBIDDEN/12/index r【已解决】
414 1
|
API 索引
Elasticsearch Index Shard Allocation 索引分片分配策略
Elasticsearch Index Shard Allocation 索引分片分配策略
422 1
|
索引
Elasticsearch exception [type=illegal_argument_exception, reason=index [.1] is the write index for data stream [slowlog] and cannot be deleted]
在 Elasticsearch 中,你尝试删除的索引是一个数据流(data stream)的一部分,而且是数据流的写入索引(write index),因此无法直接删除它。为了解决这个问题,你可以按照以下步骤进行操作:
1243 0
|
API
Elasticsearch - cluster_block_exception [FORBIDDEN/12/index read-only / allow delete (api)]
Elasticsearch - cluster_block_exception [FORBIDDEN/12/index read-only / allow delete (api)]
280 0
Elasticsearch - cluster_block_exception [FORBIDDEN/12/index read-only / allow delete (api)]
|
存储 缓存 自然语言处理
Elasticsearch倒排索引(二)深入Term Index
Elasticsearch倒排索引(二)深入Term Index
759 0
Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]
Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]
Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]
|
运维 Linux API
【ElasticSearch实战】——ElasticSearch6 报错FORBIDDEN/12/index read-only / allow delete (api)
【ElasticSearch实战】——ElasticSearch6 报错FORBIDDEN/12/index read-only / allow delete (api)
656 0
|
6月前
|
JSON 安全 数据可视化
Elasticsearch(es)在Windows系统上的安装与部署(含Kibana)
Kibana 是 Elastic Stack(原 ELK Stack)中的核心数据可视化工具,主要与 Elasticsearch 配合使用,提供强大的数据探索、分析和展示功能。elasticsearch安装在windows上一般是zip文件,解压到对应目录。文件,elasticsearch8.x以上版本是自动开启安全认证的。kibana安装在windows上一般是zip文件,解压到对应目录。elasticsearch的默认端口是9200,访问。默认用户是elastic,密码需要重置。
3243 0