GithubHelp home page GithubHelp logo

elasticsearchclient.jl's Introduction

ElasticsearchClient.jl

Coverage Status

This library was inspired by elasticsearch-ruby and most of the implementation was taken from there.

There are two main modules: ElasticTransfort and API.

  • ElasticTransport is responsible for low-level interactions with Elasticsearch and it allows requests to be performed using HTTP parameters.
  • API suggests a high level API that corresponds with Elasticsearch API. Currently not all API methods are implemented, so help is needed.

Example of using ElasticTransort

using ElasticsearchClient

# Client is exported from ElasticTransport
client = ElasticsearchClient.Client(host=(host="localhost", port=9200, scheme="http"))

perform_request(client, "GET", "/_search")

Example of using API

using ElasticsearchClient

client = ElasticsearchClient.Client()

body = (
  query=(
    match_all=Dict(),
  ),
)

# Methods are exported from API module
response = ElasticsearchClient.search(client, body=body)

@show response.body["took"]

Authentication

If you need to use authentication, you can use custom http client with additional middleware layers.

Example:

# Example from HTTP.jl docs: https://juliaweb.github.io/HTTP.jl/stable/client/#Quick-Examples
module Auth

using HTTP

function auth_layer(handler)
    # returns a `Handler` function; check for a custom keyword arg `authcreds` that
    # a user would pass like `HTTP.get(...; authcreds=creds)`.
    # We also accept trailing keyword args `kw...` and pass them along later.
    return function(req; authcreds=nothing, kw...)
        # only apply the auth layer if the user passed `authcreds`
        if authcreds !== nothing
            # we add a custom header with stringified auth creds
            HTTP.setheader(req, "X-Auth-Creds" => string(authcreds))
        end
        # pass the request along to the next layer by calling `auth_layer` arg `handler`
        # also pass along the trailing keyword args `kw...`
        return handler(req; kw...)
    end
end

# Create a new client with the auth layer added
HTTP.@client [auth_layer]

end

client = ElasticsearchClient.Client(http_client=Auth)

How to install Elasticsearch locally?

The easiest way is to use a Docker container. If you have Docker Desktop, then just copy the the docker-compose.yml:

version: '3.8'
services:
  es01:
    image: 'docker.elastic.co/elasticsearch/elasticsearch:8.8.2'
    ports:
      - '0.0.0.0:9200:9200'
    volumes:
      - esdata:/usr/share/elasticsearch/data
    restart: always
    environment:
      - node.name=es01
      - cluster.name=es_local_claster
      - cluster.initial_master_nodes=es01
      - bootstrap.memory_lock=true
      - xpack.security.enabled=false
    mem_limit: 1073741824
    ulimits:
      memlock:
        soft: -1
        hard: -1
volumes:
  esdata:
    driver: local

and run the docker-compose up command in the directory containing that file.

If you want to configure a cluster see full instructions

What's next?

More information about usage can be found in the documentation.

elasticsearchclient.jl's People

Contributors

os-esh avatar os-rss avatar

Stargazers

Nero Blackstone​ avatar Anna avatar Fábio Sodré avatar  avatar Jakub A. G. avatar Fernando Briano avatar Jun Tian avatar

Watchers

Aaron Bridges avatar James Cloos avatar A.J. Supinski avatar Tom Rodrigues avatar  avatar

elasticsearchclient.jl's Issues

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.