1. Elasticsearch concepts

What Wikipedia says

Elasticsearch is a search engine based on Lucene. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents. Elasticsearch is developed in Java and is released as open source under the terms of the Apache License. Official clients are available in Java, .NET (C#), PHP, Python, Apache Groovy, Ruby and many other languages. According to the DB-Engines ranking, Elasticsearch is the most popular enterprise search engine, followed by Apache Solr, also based on Lucene.
Source: Wikipedia – Elasticsearch

Definition from the Elastic site

Elasticsearch is a real-time distributed search and analytics engine. It allows you to explore your data at a speed and at a scale never before possible. It is used for full-text search, structured search, analytics, and all three in combination.
Source: Elastic – Getting Started

Real-world examples:

  • Wikipedia uses Elasticsearch for full-text search with highlighted snippets, plus search-as-you-type and did-you-mean suggestions.
  • The Guardian combines visitor logs with social-network data to give editors real-time feedback on the public's response to new articles.
  • Stack Overflow combines full-text search with geolocation queries and uses more-like-this to find related questions and answers.
  • GitHub uses Elasticsearch to query 130 billion lines of code.

Index = database? Comparing with MySQL

Think of an index like a database. (See: What is an Elasticsearch Index)

  • MySQL ⇒ Databases ⇒ Tables ⇒ Columns / Rows
  • Elasticsearch ⇒ Indices ⇒ Types ⇒ Documents with properties
MySQL Elasticsearch MongoDB
ColumnFieldField
RowDocumentDocument
TableIndexCollection
SchemaImplicit (mapping)Flexible schema (optional validation)
Catalog or databaseCluster instanceDatabase
ClusterClusterCluster (replica set / sharded cluster)
SQL queryQuery DSLQuery language (MQL) / Aggregation pipeline

Core terms

  • Cluster: a group of nodes that share the same cluster name.
  • Node: one server that hosts data and takes part in indexing and querying.
  • Shard: stores documents. A shard is a single Lucene instance, a low-level "worker" unit managed automatically by Elasticsearch.

Installation

Elasticsearch installation guide

Reference documents

2. Practical introduction

A Practical Introduction to Elasticsearch

3. Using Elasticsearch in a Java application


Bản tiếng Việt

1. Các khái niệm về Elasticsearch

Wikipedia nói gì về Elasticsearch

Elasticsearch là một công cụ tìm kiếm (search engine) dựa trên Lucene. Nó cung cấp một công cụ tìm kiếm toàn văn (full-text search) phân tán, hỗ trợ nhiều người thuê (multitenant), với giao diện web HTTP và các tài liệu JSON không cần schema cố định. Elasticsearch được viết bằng Java và phát hành mã nguồn mở theo giấy phép Apache License. Các client chính thức có sẵn cho Java, .NET (C#), PHP, Python, Apache Groovy, Ruby và nhiều ngôn ngữ khác. Theo bảng xếp hạng DB-Engines, Elasticsearch là công cụ tìm kiếm doanh nghiệp phổ biến nhất, tiếp theo là Apache Solr (cũng dựa trên Lucene).

Định nghĩa từ trang của Elastic

Elasticsearch là một công cụ tìm kiếm và phân tích phân tán theo thời gian thực. Nó cho phép bạn khám phá dữ liệu với tốc độ và quy mô chưa từng có. Elasticsearch được dùng cho tìm kiếm toàn văn, tìm kiếm có cấu trúc, phân tích dữ liệu, hoặc kết hợp cả ba.

Một số ví dụ thực tế:

  • Wikipedia dùng Elasticsearch để tìm kiếm toàn văn với đoạn trích được tô sáng, cùng các gợi ý search-as-you-type (tìm khi đang gõ) và did-you-mean (có phải bạn muốn tìm...).
  • The Guardian kết hợp log lượt truy cập với dữ liệu mạng xã hội để cung cấp cho biên tập viên phản hồi theo thời gian thực về mức độ đón nhận của độc giả với các bài viết mới.
  • Stack Overflow kết hợp tìm kiếm toàn văn với truy vấn theo vị trí địa lý, và dùng more-like-this để tìm các câu hỏi và câu trả lời liên quan.
  • GitHub dùng Elasticsearch để truy vấn 130 tỷ dòng code.

Index giống như database? So sánh với MySQL

Bạn có thể hình dung một index giống như một database.

  • MySQL ⇒ Databases ⇒ Tables ⇒ Columns / Rows
  • Elasticsearch ⇒ Indices ⇒ Types ⇒ Documents (gồm các properties)
MySQL Elasticsearch MongoDB
Column (cột)Field (trường)Field (trường)
Row (dòng)Document (tài liệu)Document (tài liệu)
Table (bảng)IndexCollection
SchemaNgầm định (mapping)Schema linh hoạt (có thể thêm validation)
Catalog hoặc databaseCluster instanceDatabase
ClusterClusterCluster (replica set / sharded cluster)
Truy vấn SQLQuery DSLNgôn ngữ truy vấn (MQL) / Aggregation pipeline

Các thuật ngữ cốt lõi

  • Cluster: tập hợp các node dùng chung một tên cluster.
  • Node: tương ứng với một server, chịu trách nhiệm lưu trữ dữ liệu và tham gia vào việc lập chỉ mục (indexing) và truy vấn (querying).
  • Shard: nơi lưu trữ các document. Mỗi shard là một instance Lucene độc lập, là đơn vị "worker" cấp thấp được Elasticsearch tự động quản lý.

Cài đặt

Hướng dẫn cài đặt Elasticsearch

Tài liệu tham khảo

Xem danh sách link ở phần tiếng Anh phía trên (Solr vs Elasticsearch, tài liệu Elastic, inverted index, glossary...).

2. Thực hành cơ bản với Elasticsearch

Bài hướng dẫn thực hành: A Practical Introduction to Elasticsearch

3. Dùng Elasticsearch trong ứng dụng Java

Các bài viết ví dụ về cách tạo, truy vấn và xoá index bằng Java client được liệt kê ở phần tiếng Anh phía trên.