- 掌握es中的专业术语懂得es与ik分词器的下载安装与配置掌握使用postman进行数据的增删改查
入门 简介
- elasticSearch是一个分布式,具有RestFul风格的搜索引擎支持对各种类型的数据进行搜索搜索速度快,可以提供实时的搜索服务便于水平拓展,每秒可以处理PB级海量数据提供聚合功能:可对索引中的数据进行统计分析安全:提供X-Pack进行用户验证
- 索引:相当于关系型数据库中的数据库文档:相当于关系型数据库中的一条记录,文档中可以包含一个或多个字段,是用户对数据操作的最细颗粒度对象版本:操作文档时需要用到版本的概念,文档的初始版本为1,每次的写操作会把文档版本加1,使用文档时返回给用户的最新版本字段:相当于关系型数据库中的字段,es中除了常用的数据类型之外还包含了数组,经纬度,ip地址等,不同的类型的字段支持不同的搜索功能映射:建立索引时需要定义文档的数据结构,该结构叫做映射,es提供了自动映射的功能分片:为了存储和计算海量的数据,对数据进行拆分,然后存储到计算机中分担集群的存储和计算压力,在默认情况下每个索引设置5个分片副分片:每个分片可以设置多个副分片,当主分片故障离线时,副分片会充当主分片继续服务DSL:Domain Specific Language,领域特定语言,es使用该语言来定义来定义查询,采用JSON进行表达,es将客户端请求的返回数据封装为JSON,屏蔽了各种编程语言之间的数据通信差异
https://www.elastic.co/cn/downloads/past-releases#elasticsearch
ik分词器下载https://github.com/medcl/elasticsearch-analysis-ik/releases
需要知道的是:spring boot底层有一个默认的es版本与之对应,下载对应的es版本以减少不必要的麻烦,且ik分词器的版本需要与es对应
解压zip压缩包之后进入到config目录下打开elasticSearch.yml中
- 设置cluster.name集群名称,自定义设置node.name节点名称,自定义设置数据的路径和日志的存储路径设置网络的IP地址,一般是0.0.0.0设置端口号,默认是9200设置集群的初始化主节点
# ======================== Elasticsearch Configuration ========================= # # NOTE: Elasticsearch comes with reasonable defaults for most settings. # Before you set out to tweak and tune the configuration, make sure you # understand what are you trying to accomplish and the consequences. # # The primary way of configuring a node is via this file. This template lists # the most important settings you may want to configure for a production cluster. # # Please consult the documentation for further information on configuration options: # https://www.elastic.co/guide/en/elasticsearch/reference/index.html # # ---------------------------------- Cluster ----------------------------------- # # Use a descriptive name for your cluster: # cluster.name: my-application # # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # node.name: node-1 # # Add custom attributes to the node: # #node.attr.rack: r1 # # ----------------------------------- Paths ------------------------------------ # # Path to directory where to store the data (separate multiple locations by comma): # path.data: E:Linux分词器7.12.1elasticsearch-7.12.1-windows-x86_64elasticsearch-7.12.1data # # Path to log files: # path.logs: E:Linux分词器7.12.1elasticsearch-7.12.1-windows-x86_64elasticsearch-7.12.1logs # # ----------------------------------- Memory ----------------------------------- # # Lock the memory on startup: # #bootstrap.memory_lock: true # # Make sure that the heap size is set to about half the memory available # on the system and that the owner of the process is allowed to use this # limit. # # Elasticsearch performs poorly when the system is swapping the memory. # # ---------------------------------- Network ----------------------------------- # # By default Elasticsearch is only accessible on localhost. Set a different # address here to expose this node on the network: # network.host: 0.0.0.0 # # By default Elasticsearch listens for HTTP traffic on the first free port it # finds starting at 9200. Set a specific HTTP port here: # http.port: 9200 # # For more information, consult the network module documentation. # # --------------------------------- Discovery ---------------------------------- # # Pass an initial list of hosts to perform discovery when this node is started: # The default list of hosts is ["127.0.0.1", "[::1]"] # #discovery.seed_hosts: ["host1", "host2"] # # Bootstrap the cluster using an initial set of master-eligible nodes: # cluster.initial_master_nodes: ["node-1"] # # For more information, consult the discovery and cluster formation module documentation. # # ---------------------------------- Various ----------------------------------- # # Require explicit names when deleting indices: # #action.destructive_requires_name: true安装ik分词器
解压ik分词器后将文件夹复制到es中的plugins下,ik分词器支持中文分词
配置环境变量与配置Java的环境变量一致进入到es的bin目录下拷贝路径进入电脑的高级系统设置path下粘贴路径
window启动:打开命令行窗口运行:elasticsearch.bat
linux启动:elasticsearch.sh
访问localhost:9200出现如下界面表示配置成功
1.查看健康状况
curl -X GET "192.1686.230.141:9200/_cat/health?v"
cluster:节点名称
status:状态(green,yellow,red)
node.total:节点数量
node.data:节点数据
shards:分片数量
2.查看节点
curl -X GET "192.168.230.141:9200/_cat/nodes?v"
ip:ip地址
heap.percent:堆占用量
ram.percenr:内存占用量
cpu:cpu占用量
node.role:节点角色
4.创建索引
curl -X PUT "192.168.230.141:9200/(indexName)"
5.删除索引
curl -X DELETE "192.230.141:9200/(indexName)"
6.插入(修改)文档(一行数据)(PUT)
7.查看文档数据(GET)
8.删除文档数据(一行数据)(DELETE)
192.168.230.141:9200/(indexName)/_doc/(id) #插入时使用josn格式插入数据
{
"title":"Hello",
"content":"ElasticSearch"
}
9.数据查询
192.168.230.141:9200/(indexName)/_search #查询索引下的所有数据 192.168.230.141:9200/(indexName)/_search?q=FieldName:(words) #查询该索引下FieldName属性,words的为条件的数据。先对words词条进行拆分然后再进行数据匹配 192.168.230.141:9200/(indexName)/_search #多字段匹配查询数据
{
"query":{
"multi_match":{
"query":"需要匹配的词条",
"fields":["字段1","字段2"]
}
}
}



