Elastic Query Language

Elastic search is a high performance search and analytic engine. It is highly scalable, super fast, easier to use and near real time JSON documented data server. But,

Elastic search is just a search engine. It is not a data store and it’s never an replacement for traditional SQL servers.

Elastic search is an REST API and one can talk with the Elastic through simple API calls. Let’s look at some of the basic Elastic queries and their relation between SQL syntax.

Basics of Elastic

The basic unit of Elastic search is a document which is equivalent to a SQL record. A collection of documents makes up an index which is equal to an SQL table. Many Indexes are tied up together to form an Node. A Node is simply an elastic server and the nodes are clustered together to form an Elastic cluster.

  • Elastic has a simple syntax to get all records from a index.When a match_all is fired, elastic sets the score of all documents as 1.0 . This score can be changed by the ‘boost’ parameter.The POST body is as follows,
  • The LIMIT syntax filters the number of records in SQL. The ‘size’ property in Elastic search helps to specify the size of records to be retrieved.By default, elastic retrieves only 10 documents.
  • The ‘size’ property can be used to specify the offset and the starting point of the document can be set by the ‘from’ property.By default, the elastic configuration sets the index.max_result_window to 10,000. Hence the from + size cannot exceed this limit.
  • The elastic sort property helps us to order the document either in ascending or descending order.To sort by the document score , special field name _score should be used.To sort by index of the document, _doc should be used. When sorting, the sorted fields are loaded into the memory, hence there should be an enough memory in each shard. For a string field to be sorted, it must not be tokenized.
  • Elastic allows to specify the fields of the document to be retrieved using the _source query. The list of fields need to be sent as an array.
  • Elastic match query is useful to search documents which matches a keyword or an phrase. Match query is an Elastic equivalent of SQL like operator. Match_phrase query does an exact match of the specified phrase.
  • The bool queries are useful in compounding multiple smaller queries and it does the usual AND , OR , NOT operations.The elastic syntax is as follows,

These are the basic queries in elastic to get up and running. Let’s explore more in next post. Until then, Happy Elastic searching. Happy New Year too.


Originally published at www.athavankanapuli.com.