Lua client for Elasticsearch
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.travis Updated lua version to 5.3.3 and es version to 2.4.1 Oct 26, 2016
docs Fixed luarocks command to install elasticsearch Jan 10, 2017
.gitignore Added basic structure of documentation Jul 26, 2016
.travis.yml Set version 1.0.1 and tagged as v1.0.1 Jul 17, 2018
set-version New set-version script for creating releases Jul 17, 2018


Build Status Coverage Status

Join the chat at License

LuaRocks Lua

A low level client for Elasticsearch written in Lua.

In accordance with other official low level clients, the client accepts associative arrays in the form of lua table as parameters.


  1. One-to-one mapping with REST API and other language clients.
  2. Proper load balancing across all nodes.
  3. Pluggable and multiple connection, selection strategies and connection pool.
  4. Console logging facility.
  5. Almost every parameter is configurable.

Elasticsearch Version Matrix

Elasticsearch Version elasticsearch-lua Branch
>= 2.0, < 5.0 2.x.y

Lua Version Requirements

elasticsearch-lua works for lua >= 5.1 version.


It can be installed using luarocks

  [sudo] luarocks install elasticsearch


The complete documetation is here.

Create elasticsearch client instance:

  local elasticsearch = require "elasticsearch"

  local client = elasticsearch.client{
    hosts = {
      { -- Ignoring any of the following hosts parameters is allowed.
        -- The default shall be set
        protocol = "http",
        host = "localhost",
        port = 9200
    -- Optional parameters
    params = {
      pingTimeout = 2
  -- Will connect to default host/port
  local client = elasticsearch.client()

Full list of params:

  1. pingTimeout : The timeout of a connection for ping and sniff request. Default is 1.
  2. selector : The type of selection strategy to be used. Default is RoundRobinSelector.
  3. connectionPool : The type of connection pool to be used. Default is StaticConnectionPool.
  4. connectionPoolSettings : The connection pool settings,
  5. maxRetryCount : The maximum times to retry if a particular connection fails.
  6. logLevel : The level of logging to be done. Default is warning.

Standard call

local param1, param2 = client:<func>()

param1: Stores the data returned or nil on error

param2: Stores the HTTP status code on success or the error message on failure

Getting info of elasticsearch server

local data, err = client:info()

Index a document

Everything is represented as a lua table.

local data, err = client:index{
  index = "my_index",
  type = "my_type",
  id = "my_doc",
  body = {
    my_key = "my_param"

Get a document

data, err = client:get{
  index = "my_index",
  type = "my_type",
  id = "my_doc"

Delete a document

data, err = client:delete{
  index = "my_index",
  type = "my_type",
  id = "my_doc"

Searching a document

You can search a document using either query string:

data, err = client:search{
  index = "my_index",
  type = "my_type",
  q = "my_key:my_param"

Or either a request body:

data, err = client:search{
  index = "my_index",
  type = "my_type",
  body = {
    query = {
      match = {
        my_key = "my_param"

Update a document

data, err = client:update{
  index = "my_index",
  type = "my_type",
  id = "my_doc",
  body = {
    doc = {
      my_key = "new_param"


Feel free to file issues and submit pull requests – contributions are welcome. Please try to follow the code style used in the repository.


elasticsearch-lua is licensed under the MIT license.