8.2. ElasticSearch

ElasticSearch database connector for Haka.

Usage:

local elasticsearch = require('misc/elasticsearch')

8.2.1. API

elasticsearch.connector(host) → connector
Parameters:
  • host (string) – ElasticSearch host name.

Create a new ElasticSearch connector and connect to the given address.

object elasticsearch.Connector
<Connector>:newindex(index, data)
Parameters:
  • index (string) – ElasticSearch index name.
  • data (table) – Data to pass to the ElasticSearch server (check the ElasticSearch API for more detail about it).

Create a new index in the ElasticSearch database.

<Connector>:insert(index, type, id, data)
Parameters:
  • index (string) – ElasticSearch index name.
  • type (string) – Object type.
  • id (string) – Optional object id (can be nil).
  • data (table) – Object data.

Insert a new object in the ElasticSearch database.

<Connector>:update(index, type, id, data)
Parameters:
  • index (string) – ElasticSearch index name.
  • type (string) – Object type.
  • id (string) – Object id.
  • data (table) – Object data to update.

Update some data of an existing object in the ElasticSearch database.

<Connector>:timestamp(time) → formated
Parameters:
Returns:
  • formated (string) – Formated timestamp in ElasticSearch format.

Render a timestamp to the standard ElasticSearch format.

<Connector>:genid() → id
Returns:
  • id (string) – Unique id.

Generate a unique id which can be used as an object id.

8.2.2. Example

local elasticsearch = require('misc/elasticsearch')

local connector = elasticsearch.connector('http://127.0.0.1:9200')

connector:insert("myindex", "mytype", nil, { name="object name" })