Skip to content

Commit

Permalink
Added docs for getting documents
Browse files Browse the repository at this point in the history
  • Loading branch information
DhavalKapil committed Jul 22, 2016
1 parent 813fa72 commit a5db708
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions docs/getting_documents.rst
@@ -1,2 +1,73 @@
Getting Documents
=================

Like indexing documents, there are several ways to 'get' document(s) from
the Elasticsearch server using `elasticsearch-lua`_.

Getting Single Document
-----------------------

To get a single document, provide **index**, **type** and **id** of the
document.

.. code-block:: lua
local res, status = client:get{
index = "my_index",
type = "my_type",
id = "my_id"
}
Getting Multiple Documents
--------------------------

Elasticsearch supports getting multiple documents using a single request. It is
advised to use this method in case you want to retrieve multiple documents. You
need to pass an array of Lua tables to the MGET API. Each table represents
details about one document and consists of three fields **_index**, **_type**
and **_id**.

.. code-block:: lua
local res, status = client:mget{
body = {
docs = {
-- First document
{
["_index"] = "my_index1",
["_type"] = "my_type1",
["_id"] = "my_id1"
},
-- Second document
{
["_index"] = "my_index2",
["_type"] = "my_type2",
["_id"] = "my_id2"
}
}
}
}
In case every document has the same **index** or **type**, they can be specified
separately instead of passing them in every document table.

.. code-block:: lua
local res, status = client:mget{
index = "my_index",
type = "my_type",
body = {
docs = {
-- First document
{
["_id"] = "my_id1"
},
-- Second document
{
["_id"] = "my_id2"
}
}
}
}
.. _elasticsearch-lua: https://github.com/DhavalKapil/elasticsearch-lua

0 comments on commit a5db708

Please sign in to comment.