当前位置:网站首页>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
未完待续......
边栏推荐
- (验证文件)validateJarFile...报错
- 大龄码农从北京到荷兰的躺平生活
- 2022高压电工特种作业证考试题库及在线模拟考试
- Complete test process [Hangzhou multi tester] [Hangzhou multi tester \wang Sir]
- How unittest knows the execution time of each test case
- 09 Minimum Spanning Tree highway
- Web page design example assignment -- Introduction to Henan cuisine (4 pages) web final assignment design web page_ Dessert and gourmet college students' web design homework finished product
- 开关电源电路图及原理12v分析-详细版
- 2022年R1快開門式壓力容器操作考試題庫及模擬考試
- Heartless sword English Chinese bilingual poem 001 Spring outing
猜你喜欢

Memory image of various data types in C language

为什么芯片设计也需要「匠人精神」?

整了20张高清数据分析全知识地图,强烈建议收藏!

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

leetcode417. Pacific Atlantic current problems (medium)

Zhenxiang, Huawei gives n+1 for voluntary resignation

2022 molten welding and thermal cutting work license and simulation examination

Project workspace creation steps - Zezhong ar automated test tool

(湖南科技大学oj作业)问题 G: 串的模式匹配

Learn about Prometheus from 0 to 1
随机推荐
jsp页面初始加载方式
药物评价指标
[leetcode daily question] Repeat overlay string matching
JDBC debugging error, ask for guidance
solr(一)solr的安装及权限控制
[ISITDTU 2019]EasyPHP
[learn FPGA programming from scratch -18]: quick start chapter - operation steps 2-6- VerilogHDL sequential circuit syntax analysis (taking the counter as an example)
DHCP protocol instantiation analysis
leetcode417. 太平洋大西洋水流问题(中等)
Differences between list and set access elements
为什么芯片设计也需要「匠人精神」?
Analysis of time complexity and space complexity
信息收集常用工具及命令
Pyqt5 enables the qplaintextedit control to support line number display
Implementation of VGA protocol based on FPGA
[ISITDTU 2019]EasyPHP
Time processing logic for the last 7 days, the last 10 days, and the last 90 days
What is a generic? Why use generics? How do I use generics? What about packaging?
2022 high altitude installation, maintenance and demolition test simulation 100 questions and online simulation test
TC8:UDP_ MessageFormat_ 01-02