当前位置:网站首页>Elasitcsearch基础学习笔记(1)
Elasitcsearch基础学习笔记(1)
2022-06-11 16:34:00 【chenxiky】
一.基本概念
数据的分类
1.结构化数据:指具有固定格式或有限⻓度的数据,如数据库,元数据等。 对于结构化数据,我们⼀般都是可以通过关系型数据库(mysql,oracle等)的 table 的⽅ 式存储和搜索,也可以建⽴索引。通过b-tree等数据结构快速搜索数据。
2.⾮结构化数据:全⽂数据,指不定⻓或⽆固定格式的数据,如邮件,word⽂档等。 对于⾮结构化数据,也即对全⽂数据的搜索主要有两种⽅法:顺序扫描法,全⽂搜索法。
全⽂搜索
对⾮结构化数据进行信息提取出来,重新组织,使其变得有⼀定结构,然后对这些有⼀定结构的数据进⾏搜索,从⽽达到搜索相对较快的⽬的。这 种⽅式就构成了全⽂搜索的基本思路。这部分从⾮结构化数据中提取出的然后重新组织的信 息,我们称之索引。
什么是全⽂搜索引擎?
⼯作原理:是计算机索 引程序通过扫描⽂章中的每⼀个词,对每⼀个词建⽴⼀个索引,指明该词在⽂章中出现的次数和位 置,当⽤户查询时,检索程序就根据事先建⽴的索引进⾏查找,并将查找的结果反馈给⽤户的。
搜索引擎主要有 :Lucene 、Solr 、Elastic search。
适合全⽂索引引擎的场景
搜索的数据对象是⼤量的⾮结构化的⽂本数据。
⽂本数据量达到数⼗万或数百万级别,甚⾄更多。
⽀持⼤量基于交互式⽂本的查询。 需求⾮常灵活的全⽂搜索查询。
对安全事务,⾮⽂本数据操作的需求相对较少的情况。
Elasticsearch Elasticsearch是⼀个开源,是⼀个基于Apache Lucene库构建的Restful搜索引擎.
主要功能:分布式搜索 数据分析 分组和聚合
应⽤场景:维基百科 Stack Overflow GitHub 电商⽹站 ⽇志数据分析 商品价格监控⽹站 BI系统 站内搜索 篮球论坛
二.Elasticsearch基本目录介绍及大概结构

索引(index):⼀个索引可以理解成⼀个关系型数据库。
类型(type): ⼀种type就像⼀类表,⽐如user表,order表。 注意: ES 5.x中⼀个index可以有多种type。 ES 6.x中⼀个index只能有⼀种type。 ES 7.x以后已经移除type这个概念。
映射(mapping) :mapping定义了每个字段的类型等信息。相当于关系型数据库中的表结构。 ⽂档(document) ⼀个document相当于关系型数据库中的⼀⾏记录。
字段(field) :相当于关系型数据库表的字段 集群(cluster) 集群由⼀个或多个节点组成,⼀个集群有⼀个默认名称"elasticsearch"。
节点(node) :集群的节点,⼀台机器或者⼀个进程。
分⽚和副本(shard) :副本是分⽚的副本。分⽚有主分⽚(primary Shard)和副本分⽚(replica Shard)之分。 ⼀个Index数据在物理上被分布在多个主分⽚中,每个主分⽚只存放部分数据。 每个主分⽚可以有多个副本,叫副本分⽚,是主分⽚的复制。
elasticsearch使⽤RESTful⻛格api来设计的:RESTful是⼀种架构的规范与约束、原则,符合这种规范的架构就是RESTful架构。

三.ES基本使用
1.索引的介绍和使⽤
新增索引:PUT "localhost:9200/nba"
获取索引:GET "localhost:9200/nba"
删除索引:DELETE "localhost:9200/nba"
批量获取索引:GET "localhost:9200/nba,cba"
获取所有索引:GET "localhost:9200/_all" GET "localhost:9200/_cat/indices?v"
2.映射的介绍和使⽤
新增映射 PUT "localhost:9200/nba/_mapping"
{ "properties": { "name": { "type": "text" }, "team_name": { "type": "text" }, "position": { "type": "keyword" }, "play_year": { "type": "keyword" }, "jerse_no": { "type": "keyword" 响应 获取 请求 响应 批量获取 请求 } } }获取映射 GET "localhost:9200/xdclass/_mapping"
批量获取:GET "localhost:9200/nba,cba/mapping"
获取所有:1.X GET "localhost:9200/_mapping";2.GET "localhost:9200/_all/_mapping"
修改映射:PUT "localhost:9200/nba/_mapping"
{
"properties": {
"name": {
"type": "text"
},
"team_name": {
"type": "text"
},
"position": {
"type": "keyword"
},
"play_year": {
"type": "keyword"
},
"jerse_no": {
"type": "keyword"
},
"country": {
"type": "keyword"
}
}
}3.⽂档的增删改查
新增⽂档:1.PUT localhost:9200/nba/_doc/1 (指定id) 注:指定需要用PUT
2.POST localhost:9200/nba/_doc (不指定id) 不需要指定
{ "name":"库⾥", "team_name":"勇⼠", "position":"组织后卫", "play_year":"10", "jerse_no":"30" }
查看⽂档:GET localhost:9200/nba/_doc/1
查看多个⽂档:1.POST localhost:9200/_mget
{"docs" : [ { "_index" : "nba", "_type" : "_doc", "_id" : "1" }, { "_index" : "nba", "_type" : "_doc", "_id" : "2" } ] }
2.POST localhost:9200/nba/doc/mget
{ "docs" : [ { "_id" : "1" }, { "_id" : "2" } ] }
3.GET localhost:9200/nba/doc/mget
{ "ids" : ["1", "2"] }
修改⽂档: POST localhost:9200/nba/_update/1
{ "doc": { "name": "哈登", "team_name": "⽕箭", "position": "双能卫", "play_year": "10", "jerse_no": "13" } }
向_source字段,增加⼀个字段:POST localhost:9200/nba/_update/1
{ "script": "ctx._source.age = 18" }
从_source字段,删除⼀个字段:POST localhost:9200/nba/_update/1
{ "script": "ctx._source.remove(\"age\")" }
根据参数值,更新指定⽂档的字段:POST localhost:9200/nba/_update/1
{ "script": { "source": "ctx._source.age += params.age", "params": { "age": 4 } } }
upsert 当指定的⽂档不存在时,upsert参数包含的内容将会被插⼊到索引中,作为⼀个 新⽂档;如果指定的⽂档存在,ElasticSearch引擎将会执⾏指定的更新逻辑。
POST localhost:9200/nba/_update/3
{ "script": { "source": "ctx._source.allstar += params.allstar", "params": { "allstar": 4 } }, "upsert": { "allstar": 1 } }
删除⽂档:DELETE localhost:9200/nba/_doc/1
未完待续......
边栏推荐
猜你喜欢

Student website template brown cake dessert website design - brown cake dessert shop (4 pages) gourmet dessert website production final assignment finished product_ Fresh fruit web design final assign

1267_FreeRTOS启动第一个任务接口prvPortStartFirstTask实现分析
![[sword finger offer] 21 Adjust array order so that odd numbers precede even numbers](/img/ba/8fa84520bacbc56ce7cbe02ee696c8.png)
[sword finger offer] 21 Adjust array order so that odd numbers precede even numbers

The micro service failed to connect to the cloud sentinel console and the link blank problem occurred after the connection was successful (resolved)

2022熔化焊接与热切割上岗证题目及模拟考试

How can the project manager repel the fear of being dominated by work reports?

A team of heavyweights came to the "digital transformation" arena of CLP Jinxin ice and snow sports

Pytest test framework Basics

How the autorunner automated test tool creates a project -alltesting | Zezhong cloud test

Differences between list and set access elements
随机推荐
Laravel 8 realizes database backup through task scheduling
2022年R1快开门式压力容器操作考试题库及模拟考试
How unittest knows the execution time of each test case
09 Minimum Spanning Tree highway
2022年R1快開門式壓力容器操作考試題庫及模擬考試
leetcode785. 判断二分图(中等)
2022 high voltage electrician special operation certificate examination question bank and online simulation examination
网络流媒体协议的联系与区别(RTP RTCP RTSP RTMP HLS)
[learn FPGA programming from scratch -18]: quick start chapter - operation steps 2-6- VerilogHDL sequential circuit syntax analysis (taking the counter as an example)
2022年安全员-B证国家题库及模拟考试
关联关系
2022 simulated examination question bank and simulated examination for crane driver (limited to bridge crane)
回归预测 | MATLAB实现RBF径向基神经网络多输入单输出
项目经理如何击退被工作汇报支配的恐惧感?
leetcode684. Redundant connection (medium)
RDKit教程
Laravel 8 uses passport for auth authentication and token issuance
信息收集常用工具及命令
基于文本驱动用于创建和编辑图像(附源代码)
Laravel8 implementation of sign in function