lua-resty-elasticsearch

ElasticSearch client for OpenResty / ngx_lua.

$ opm get tomas/lua-resty-elasticsearch

lua-resty-elasticsearch

ElasticSearch client for for OpenResty / ngx_lua.

Requirements

lua-resty-http

API

Synopsis

    lua_package_path "/path/to/lua-resty-http,lua-resty-elasticsearch/lib/?.lua;;";
    
    server {
        location /test_es {
            content_by_lua '
                local cjson = require "cjson"
                local elasticsearch = require "resty.elasticsearch"
                local es = elasticsearch:new({"http://localhost:9200"})
    
                local data, err = es:info()
                if not data then
                    ngx.say("info err: ", err)
                else
                    ngx.say(cjson.encode(data))
                end
                ngx.say("---------------------------")
    
                local body = {query={match_all={}}}
                local data, err = es:search({doc_type="products"})
                if not data then
                    ngx.say("search err: ", err)
                else
                    ngx.say(cjson.encode(data))
                end
                ngx.say("---------------------------")
    
                local data, err = es.cat:health()
                if not data then
                    ngx.say("cat health err: ", err)
                else
                    ngx.say(data)
                end
            ';
        }
    }

new

syntax: es = elasticsearch:new()

Creates the elasticsearch object.

ping

syntax: ok, err = es:ping()

Returns True if the cluster is up, False otherwise.

info

syntax: data, err = es:info()

Get the basic info from the current cluster.

syntax: data, err = es:search{index="index", doc_type="user", body={query={match_all={}}}}

Execute a search query and get back search hits that match the query.

Copyright and License

This module is licensed under the 2-clause BSD license.

Copyright (c) 2015-2016, by bells <bellszhu@gmail.com>

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Authors

Bells (bellszhu@gmail.com)

License

2bsd

Dependencies

pintsized/lua-resty-http >= 0.11, luajit

Versions