Elasticsearch. What is Elasticsearch and how to install it

June 12, 2016 13 Yehor Rykhnov

Elasticsearch - search system with open source code.

This article describes how to use Elasticsearch in "pure" PHP and in Yii2 framework. For convenient use of the article will be divided into several parts. Each of which would be responsible for one or several interrelated issues. Part 1, what is Elasticsearch and how to install Elasticsearch

What is Elasticsearch

Elasticsearch - search system with open source code. It is based on the library Apache Lucene (https://lucene.apache.org/core/). Apache Lucene is one of the most advanced search system with open source at the moment. It is a set of libraries for work with full-text search.

Elasticsearch - helps to realize the full power of Apache Lutsene with help simple means and mechanisms.

Elasticsearch - implements more functionality than Apache Lucene. About Elasticsearch can say that it is:

  1. The mechanism for storing documents in real time (analogue of database tables in MySQL), where each field is indexed and participate in search.
  2. Search and real-time analytics system.
  3. Scalable system.

All this is packed into a single server, you can work with him using RESTful API. Передача и получение данных в Elasticsearch sends and receives data in a JSON format. For Java has its own library but we will not consider it.

Installing Elasticsearch

Downloading/Updating the latest version of Java.

Go to website https://www.elastic.co/downloads/elasticsearch

Downloading the file, unpack, go into the folder and run the file bin/elasticsearch

I work with Ubuntu. I tried to install and run it as a service but this did not work out. In the end, I just ran it from the folder and it worked.

To work on a "pure" PHP (without framework)

Downloading library composer require elasticsearch/elasticsearch

To work in Yii2 anything extra to download is not necessary, everything is already there out of the box.

The basic concepts of storage

Clusters of Elasticsearch can contain indexes.

Index (analogue database in MySQL). Indexes can store types.

Types (similar to a table in MySQL). Can contain documents.

Documents (similar a string in MySQL table). The document consists of columns (the analog columns in MySQL).

The structure of the data storage is similar to MySQL but the difference is that each line can hold a different number of fields. Similarly the data is stored in the document-oriented databases.

The concepts of indexing in Elasticsearch

Index (noun) - MySQL database analogue.

Indexing (verb) - add recording. The analogue INSERT in SQL.

Inverted index - analogue creating indexes in MySQL.

Work with data

Tasks:

  1. Add information about employees
  2. Retrieve data about the employee
  3. Using mechanism of search
  4. Managing indexes
  5. Parameters of fields (mapping)

Next, examples will be given for "pure" PHP and Yii2 framework with help console.

Examples are taken from official documentations.

The next part: Elasticsearch. Adding data (indexing)