信息检索包含内容非常广,包含文本(搜索引擎)、 图片(以图搜索)、音频(歌曲识别)、视频等多种类型数据的检索。为了高效的检索,通常都用建立索引的方式提高检索速度。因为不同类型的数据存储格式、特征提取方法等等都是不同的,所以建立索引的类型也是不同的,检索的方法也是不同的。

对文本建立索引的数据结构是倒排索引;对关系型数据库中的数据建立索引的数据结构是B-tree;对图片建立索引,根据特征提取方式的不同,方法也是不同的,Hash、乘积量化等方法比较主流。

目前,针对不同类型的数据也有不同的工具针对不同的数据建立索引。Lucene和ElasticSearch都可以认为是全文索引的工具,是信息检索的一部分,下图清晰的介绍了全文索引的基本知识: 

     

接下来,将简单介绍ElasticSearch与Lucene、Mysql、Solr之间的关系 

1.Lucene和ElasticSearch的关系

简单直观的讲,Lucene和ElasticSearch的关系就是飞机发动机和飞机的关系:

(1) 数据结构:关系型数据库通过增加一个 索引 比如一个 B树(B-tree)索引 到指定的列上,以便提升数据检索速度。Elasticsearch 和 Lucene 使用了一个叫做倒排索引的结构来达到相同的目的。

(2) Elasticsearch 是一个开源的搜索引擎,建立在一个全文搜索引擎库 Apache Lucene™ 基础之上。无论是开源还是私有, Lucene 可以说是当下最先进、高性能、全功能的搜索引擎库。

但是 Lucene 仅仅只是一个库。为了充分发挥其功能,需要使用 Java 并将 Lucene 直接集成到应用程序中。

(3) Elasticsearch 也是使用 Java 编写的,它的内部使用 Lucene 做索引与搜索,但是它的目的是使全文检索变得简单, 通过隐藏 Lucene 的复杂性,取而代之的提供一套简单一致的 RESTful API。

然而,Elasticsearch 不仅仅是 Lucene,并且也不仅仅只是一个全文搜索引擎。简单描述:

  • 一个分布式的实时文档存储,每个字段 可以被索引与搜索
  • 一个分布式实时分析搜索引擎
  • 能胜任上百个服务节点的扩展,并支持 PB 级别的结构化或者非结构化数据

Elasticsearch 将所有的功能打包成一个单独的服务,这样你可以通过程序与它提供的简单的 RESTful API 进行通信, 可以使用自己喜欢的编程语言充当 web 客户端,甚至可以使用命令行(去充当这个客户端)。

2.ElasticSearch和Solr 的关系

Solr

Apache Solr 是一个基于名为 Lucene 的 Java 库构建的开源搜索平台。它以用户友好的方式提供 Apache Lucene 的搜索功能。

作为一个行业参与者已近十年,它是一个成熟的产品,拥有强大而广泛的用户社区。

它提供分布式索引,复制,负载平衡查询以及自动故障转移和恢复。如果它被正确部署然后管理得好,它就能够成为一个高度可靠,可扩展且容错的搜索引擎。

很多互联网巨头,如 Netflix,eBay,Instagram 和亚马逊(CloudSearch)都使用 Solr,因为它能够索引和搜索多个站点。

主要功能列表包括:

  • 全文搜索
  • 突出
  • 分面搜索
  • 实时索引
  • 动态群集
  • 数据库集成
  • NoSQL 功能和丰富的文档处理(例如 Word 和 PDF 文件)

其他方面比较:

solr集群搭建是依赖Zookeeper进行元数据管理的,elasticsearch集群则是自己管理,不需要依赖其他第三方,使得elasticsearch集群搭建更方便、快捷。

3.关系型数据库MySql和ElasticSearch的关系

从上表中可以看出:

  1. MySQL 中的数据库(DataBase),等价于 ES 中的索引(Index)。

  2. MySQL 中一个数据库下面有 N 张表(Table),等价于1个索引 Index 下面有 N 多类型(Type)。

  3. MySQL 中一个数据库表(Table)下的数据由多行(Row)多列(column,属性)组成,等价于1个 Type 由多个文档(Document)和多 Field 组成。

  4. MySQL 中定义表结构、设定字段类型等价于 ES 中的 Mapping。举例说明,在一个关系型数据库里面,Schema 定义了表、每个表的字段,还有表和字段之间的关系。与之对应的,在 ES 中,Mapping 定义索引下的 Type 的字段处理规则,即索引如何建立、索引类型、是否保存原始索引 JSON 文档、是否压缩原始 JSON 文档、是否需要分词处理、如何进行分词处理等。

  5. MySQL 中的增 insert、删 delete、改 update、查 search 操作等价于 ES 中的增 PUT/POST、删 Delete、改 _update、查 GET。其中的修改指定条件的更新 update 等价于 ES 中的 update_by_query,指定条件的删除等价于 ES 中的 delete_by_query。

  6. MySQL 中的 group by、avg、sum 等函数类似于 ES 中的 Aggregations 的部分特性。

  7. MySQL 中的去重 distinct 类似 ES 中的 cardinality 操作。

  8. MySQL 中的数据迁移等价于 ES 中的 reindex 操作。

(1)ES可以认为是NoSql的数据库,最大的缺点是不支持事物(当然,关系型数据库为了支持事物,损失很多的性能);

(2)以查询为主的情况下,可以替代部分关系型数据库的功能;

(3)关系型数据库在数据量小(百万级以下)情况下,无论是查询还是修改,都还是很有优势的;

(4)对于大量日志的分析和存储,相对于Mysql,ES还是很有优势;

DB-Engines对ElasticSearch和Mysql做了一个系统下的对比:

Editorial information provided by DB-Engines
Name Elasticsearch  Xexclude from comparison MySQL  Xexclude from comparison
Description A distributed, RESTful modern search and analytics engine based on Apache Lucene Elasticsearch lets you perform and combine many types of searches such as structured, unstructured, geo, and metric Widely used open source RDBMS
Primary database model Search engine Relational DBMS Key/Value like access via memcached API
Secondary database models Document store Document store
Key-value store
DB-Engines Ranking measures the popularity of database management systems
Trend Chart
Score 145.25
Rank #8   Overall
  #1   Search engines
Score 1167.29
Rank #2   Overall
  #2   Relational DBMS
Website www.elastic.co/­products/­elasticsearch www.mysql.com
Technical documentation www.elastic.co/­guide/­en/­elasticsearch/­reference/­current/­index.html dev.mysql.com/­doc
Developer Elastic Oracle since 2010, originally MySQL AB, then Sun
Initial release 2010 1995
Current release 6.6.0, January 2019 8.0.15, February 2019
License Commercial or Open Source Open Source Apache Version 2; Elastic License Open Source GPL version 2. Commercial licenses with extended functionallity are available
Cloud-based only Only available as a cloud service no no
DBaaS offerings (sponsored links) Database as a Service

Providers of DBaaS offerings, please contact us to be listed.

Elasticsearch Service on Elastic Cloud: Try out the official hosted Elasticsearch and Kibana offering available on AWS and GCP that's powered by the creators of Elasticsearch.
  • Azure Database for MySQL: A fully managed, scalable MySQL relational database with high availability and security built in at no extra cost
  • Google Cloud SQL: A fully-managed database service for the Google Cloud Platform
Implementation language Java C and C++
Server operating systems All OS with a Java VM FreeBSD
Linux
OS X
Solaris
Windows
Data scheme schema-free Flexible type definitions. Once a type is defined, it is persistent yes
Typing predefined data types such as float or date yes yes
XML support Some form of processing data in XML format, e.g. support for XML data structures, and/or support for XPath, XQuery or XSLT. no yes
Secondary indexes yes All search fields are automatically indexed yes
SQL Support of SQL SQL-like query language yes with proprietary extensions
APIs and other access methods Java API
RESTful HTTP/JSON API
Proprietary native API
ADO.NET
JDBC
ODBC
Supported programming languages .Net
Groovy
Java
JavaScript
Perl
PHP
Python
Ruby
Community Contributed Clients
Ada
C
C#
C++
D
Delphi
Eiffel
Erlang
Haskell
Java
JavaScript (Node.js)
Objective-C
OCaml
Perl
PHP
Python
Ruby
Scheme
Tcl
Server-side scripts Stored procedures yes yes proprietary syntax
Triggers yes by using the 'percolation' feature yes
Partitioning methods Methods for storing different data on different nodes Sharding horizontal partitioning, sharding with MySQL Cluster or MySQL Fabric
Replication methods Methods for redundantly storing data on multiple nodes yes Master-master replication
Master-slave replication
MapReduce Offers an API for user-defined Map/Reduce methods ES-Hadoop Connector no
Consistency concepts Methods to ensure consistency in a distributed system Eventual Consistency Synchronous doc based replication. Get by ID may show delays up to 1 sec. Configurable write consistency: one, quorum, all Immediate Consistency
Foreign keys Referential integrity no yes not for MyISAM storage engine
Transaction concepts Support to ensure data integrity after non-atomic manipulations of data no ACID not for MyISAM storage engine
Concurrency Support for concurrent manipulation of data yes yes table locks or row locks depending on storage engine
Durability Support for making data persistent yes yes
In-memory capabilities Is there an option to define some or all structures to be held in-memory only. Memcached and Redis integration yes
User concepts Access control   Users with fine-grained authorization concept no user groups or roles
More information provided by the system vendor
  Elasticsearch MySQL
Specific characteristics Elasticsearch is a highly scalable open source full-text search and analytics engine....
» more
 
Competitive advantages Open source, real-time index, search and analysis, horizontally scalable, distributed,...
» more
 
Typical application scenarios
» more
 
Key customers
» more
 
Market metrics More than 250 million cumulative downloads More than 100,000 community members in...
» more
 
Licensing and pricing models The Elastic Stack (Elasticsearch, Kibana, Beats, and Logstash) is free and open source...
» more
 

We invite representatives of system vendors to contact us for updating and extending the system information,
and for displaying vendor-provided information such as key customers, competitive advantages and market metrics.

Related products and services
3rd parties Dremio: Analyze your data with standard SQL and any BI tool. Accelerate your queries up to 1,000x.
» more

Elastic Cloud: Try the official hosted Elasticsearch.
» more

Dremio is like magic for MySQL accelerating your analytical queries up to 1,000x.
» more

General SQL Parser: Instantly adding parsing, decoding, analysis and rewrite SQL processing capability to your products.
» more

Progress DataDirect: Data connectivity across standard SQL and REST
» more

Navicat for MySQL is the ideal solution for MySQL/MariaDB administration and development.
» more

ScaleGrid: Fully managed MySQL-as-a-Service.
» more

CData: Connect to Big Data & NoSQL through standard Drivers.
» more

Azure Database for MySQL provides fully managed, enterprise-ready community MySQL database as a service
» more

We invite representatives of vendors of related products to contact us for presenting information about their offerings here.

More resources
  Elasticsearch MySQL
DB-Engines blog posts

PostgreSQL is the DBMS of the Year 2017
2 January 2018, Paul Andlinger, Matthias Gelbmann

Elasticsearch moved into the top 10 most popular database management systems
3 July 2017, Matthias Gelbmann

MySQL, PostgreSQL and Redis are the winners of the March ranking
2 March 2016, Paul Andlinger

show all

MariaDB strengthens its position in the open source RDBMS market
5 April 2018, Matthias Gelbmann

The struggle for the hegemony in Oracle's database empire
2 May 2017, Paul Andlinger

Microsoft SQL Server is the DBMS of the Year
4 January 2017, Matthias Gelbmann, Paul Andlinger

show all

Recent citations in the news

Toshi: A full text search engine modeled after Elasticsearch
14 January 2019, JAXenter

Data Silos and Breaches: Building a Long-term Security Operations Platform with Elasticsearch
25 January 2019, TDWI

Another Bank Found in Elasticsearch Database Leaks
24 January 2019, Infosecurity Magazine

Online casino group leaks information on 108 million bets, including user details
21 January 2019, ZDNet

James Spiteri on why security teams need Elastic Search -
23 January 2019, Enterprise Times

provided by Google News

How to create tables and add data to MySQL database with MySQL Workbench
8 February 2019, TechRepublic

Highly Available MySQL Clustering at WePay Using Orchestrator, Consul and HAProxy
10 February 2019, InfoQ.com

MySQL database management vulnerability opens the door to data theft
21 January 2019, SiliconANGLE News

Love data? Learn MySQL for a measly $11 with this online course.
23 January 2019, Mashable

MySQL Design Flaw Allows Malicious Servers to Steal Files from Clients
21 January 2019, BleepingComputer

provided by Google News

Job opportunities

Return to Work Program
Netflix, Los Gatos, CA

Frontend Software Engineer (React) - Chicago, IL
Telnyx, Chicago, IL

Data Scientist / Engineer
IBM, Armonk, NY

Data Engineer (Entry-Level) - 2010953
Software Engineering Institute, Arlington, VA

Associate Engineer
Conde Nast, New York, NY

Database Administrator
etouch, Mountain View, CA

Database Administrator
LT Consulting LLC, Reston, VA

Database Administrator
Hagen Software, Washington, DC

Database Administrator
Leidos, Reston, VA

Database Administrator
QVine Corporation, Reston, VA

参考:

全文搜索引擎 ElasticSearch 还是 Solr?

System Properties Comparison Elasticsearch vs. MySQL

ElasticSearch 基本原理(三)ElasticSearch与Lucene、Solr、Mysql的关系相关推荐

  1. ElasticSearch 基本原理之全文检索

    一.开篇几个问题 1.大规模数据如何检索? 当系统数据量上了10亿.100亿条的时候,我们在做系统架构的时候通常会从以下角度去考虑: 1)用什么数据库好?(MySQL.sybase.Oracle.达梦 ...

  2. Elasticsearch(三)——Es搜索(简单使用、全文查询、复合查询)、地理位置查询、特殊查询、聚合操作、桶聚合、管道聚合

    Elasticsearch(三)--Es搜索(简单使用.全文查询.复合查询).地理位置查询.特殊查询.聚合操作.桶聚合.管道聚合 一.Es搜索 这里的 Es 数据博主自己上网找的,为了练习 Es 搜索 ...

  3. Elasticsearch 基本原理和概念(四)

    今天和大家分析es基本原理和概念: 从上面的例子中,我们看到了很多熟悉又陌生的概念,比如索引.文档等等.这些概念 和我们平时看到的数据库里的比如索引有什么区别呢? 举个例子,现在我们要保存唐宋诗词,数 ...

  4. ElasticSearch基本原理和分布式文件系统

    目录 阶段一:Elasticsearch概念与架构 Elasticsearch的功能 Elasticsearch-Linux安装 Elasticsearch核心概念 Elasticsearch基础分布 ...

  5. 在kibana中查询elasticsearch数据的方法(lucene和kql语法)

    kibana中查询elasticsearch数据的方法 1.  Lucene查询语法 Kibana查询语言基于Lucene查询语法. 为了执行一个文本搜索,可以简单的输入一个文本字符串.例如,如果你想 ...

  6. ElasticSearch学习(三)——Windows集群部署

    文章名称 地址 ElasticSearch学习(一)--概述 前往 ElasticSearch学习(二)--索引.文档简单操作 前往 ElasticSearch学习(三)--Windows 集群部署 ...

  7. elasticsearch 第三篇(安装篇)

    *nux下安装 在*nux下,es官方已提供编译的deb和rpm包,但是需要保证已安装安装java虚拟环境(目前es1.6和1.7版本均可选择1.8版本java),安装步骤如下: 1.下载ES deb ...

  8. Elasticsearch学习之Elasticsearch的介绍和基本使用

    Elasticsearch 一)ES的基本介绍 1. Elasticsearch 是什么 2. Eelasticsearch的作用 3. Elasticsearch,Solr和Lucene三者之间的关 ...

  9. ElasticSearch简介及ElasticSearch部署、原理和使用介绍

    ElasticSearch简介及ElasticSearch部署.原理和使用介绍 第一章:elasticsearch简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式 ...

最新文章

  1. 26.angularJS $routeProvider
  2. AcWing算法提高课 Level-3 第二章 搜索
  3. Python学习笔记:常用第三方模块3
  4. 《深入.NET平台和C# 编程》内部测试 笔试题
  5. android 通过广播唤醒被杀死的app
  6. 《剑指offer》按之字行顺序打印二叉树
  7. python安装地是什么_如何安装python
  8. java基础—GUI概述
  9. 使用tftpd32烧写内核(拯救你的“砖”)
  10. python读awx云图_使用python获取实时卫星云图
  11. 毛球科技论述区块链之符号理论(上)
  12. httpc客户端API
  13. tensorflow机器学习之利用CNN卷积神经网络进行面部表情识别的实例代码
  14. 电脑录音,台式电脑如何录音_怎么电脑录音-win7之家
  15. 智能经济时节已至,百度智能云扬起风帆
  16. HTML5 canvas 参考手册
  17. torch.manual_seed(seed)
  18. DaVinci:键 - 键混合器
  19. [cf] 752 div2 B. XOR Specia-LIS-t
  20. SQL之数据定义、数据操纵

热门文章

  1. 【马士兵】Python基础--04(分支结构)
  2. python中布尔值是什么意思_Python中的布尔值
  3. 21T2-COMP9024-week02 lec02
  4. 9024:单链表的遍历与长度计算
  5. 饼图加引导线_PPT里的饼图,如何显示引导线?
  6. QT 事件类型1000个你知道多少?
  7. 常见Web漏洞的修复方法
  8. python socket实例
  9. 线路通寻线器是网络工程技术人员的新选择
  10. max9526——PAL/NTSC解码芯片