All Projects → danielberkompas → Elasticsearch Elixir

danielberkompas / Elasticsearch Elixir

Licence: mit
No-nonsense Elasticsearch library for Elixir

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Elasticsearch Elixir

Elk Kubernetes
This repo shows how to configure complete EFK stack on top of Kubernetes
Stars: ✭ 294 (-9.54%)
Mutual labels:  elasticsearch
Elasticsearch Py
Official Elasticsearch client library for Python
Stars: ✭ 3,486 (+972.62%)
Mutual labels:  elasticsearch
Go Elasticsearch
The official Go client for Elasticsearch
Stars: ✭ 3,817 (+1074.46%)
Mutual labels:  elasticsearch
Aws Es Kibana
AWS ElasticSearch Kibana Proxy
Stars: ✭ 297 (-8.62%)
Mutual labels:  elasticsearch
Fast Elasticsearch Vector Scoring
Score documents using embedding-vectors dot-product or cosine-similarity with ES Lucene engine
Stars: ✭ 304 (-6.46%)
Mutual labels:  elasticsearch
Elasticsearch Analysis Vietnamese
Vietnamese Analysis Plugin for Elasticsearch
Stars: ✭ 304 (-6.46%)
Mutual labels:  elasticsearch
Hastic Server
Hastic data management server for analyzing patterns and anomalies from Grafana
Stars: ✭ 292 (-10.15%)
Mutual labels:  elasticsearch
Ariadna
Geocoder Ariadna on ElasticSearch with OpenStreetMap
Stars: ✭ 320 (-1.54%)
Mutual labels:  elasticsearch
Wazuh Ruleset
Wazuh - Ruleset
Stars: ✭ 305 (-6.15%)
Mutual labels:  elasticsearch
Xboot
基于Spring Boot 2.x的一站式前后端分离快速开发平台XBoot 微信小程序+Uniapp 前端:Vue+iView Admin 后端:Spring Boot 2.x/Spring Security/JWT/JPA+Mybatis-Plus/Redis/Elasticsearch/Activiti 分布式限流/同步锁/验证码/SnowFlake雪花算法ID 动态权限 数据权限 工作流 代码生成 定时任务 社交账号 短信登录 单点登录 OAuth2开放平台 客服机器人 数据大屏 暗黑模式
Stars: ✭ 3,432 (+956%)
Mutual labels:  elasticsearch
Elasticsearch loader
A tool for batch loading data files (json, parquet, csv, tsv) into ElasticSearch
Stars: ✭ 300 (-7.69%)
Mutual labels:  elasticsearch
Sysmonsearch
Investigate suspicious activity by visualizing Sysmon's event log
Stars: ✭ 302 (-7.08%)
Mutual labels:  elasticsearch
Elasticsearch Cloud Deploy
Deploy Elasticsearch on the cloud easily
Stars: ✭ 308 (-5.23%)
Mutual labels:  elasticsearch
Elasticsearchbundle
Symfony bundle for Elasticsearch with steroids
Stars: ✭ 296 (-8.92%)
Mutual labels:  elasticsearch
Calaca
Search UI for Elasticsearch
Stars: ✭ 318 (-2.15%)
Mutual labels:  elasticsearch
Serilog Sinks Elasticsearch
A Serilog sink that writes events to Elasticsearch
Stars: ✭ 291 (-10.46%)
Mutual labels:  elasticsearch
Peek
Take a peek into your Rails applications.
Stars: ✭ 3,153 (+870.15%)
Mutual labels:  elasticsearch
Zombodb
Making Postgres and Elasticsearch work together like it's 2021
Stars: ✭ 3,781 (+1063.38%)
Mutual labels:  elasticsearch
Springy Store Microservices
Springy Store is a conceptual simple μServices-based project using the latest cutting-edge technologies, to demonstrate how the Store services are created to be a cloud-native and 12-factor app agnostic. Those μServices are developed based on Spring Boot & Cloud framework that implements cloud-native intuitive, design patterns, and best practices.
Stars: ✭ 318 (-2.15%)
Mutual labels:  elasticsearch
Elasticsearch Dsl Py
High level Python client for Elasticsearch
Stars: ✭ 3,388 (+942.46%)
Mutual labels:  elasticsearch

Elasticsearch

Hex.pm Build Status Coverage Status

A simple, no-nonsense Elasticsearch library for Elixir. Highlights include:

  • No DSLs. Interact directly with the Elasticsearch JSON API.
  • Zero-downtime index (re)building. Via Mix.Tasks.Elasticsearch.Build task.
  • Dev Tools. Helpers for running Elasticsearch as part of your supervision tree during development.

Installation

Add elasticsearch to your list of dependencies in mix.exs:

def deps do
  [
    {:elasticsearch, "~> 1.0.0"}
  ]
end

Then, create an Elasticsearch.Cluster in your application:

defmodule MyApp.ElasticsearchCluster do
  use Elasticsearch.Cluster, otp_app: :my_app
end

Once you have created your cluster, add it to your application's supervision tree:

children = [
  MyApp.ElasticsearchCluster
]

Finally, you can issue requests to Elasticsearch using it.

Elasticsearch.get(MyApp.ElasticsearchCluster, "/_cat/health")

Configuration

See the annotated example configuration below.

config :my_app, MyApp.ElasticsearchCluster,
  # The URL where Elasticsearch is hosted on your system
  url: "http://localhost:9200",

  # If your Elasticsearch cluster uses HTTP basic authentication,
  # specify the username and password here:
  username: "username",
  password: "password",

  # If you want to mock the responses of the Elasticsearch JSON API
  # for testing or other purposes, you can inject a different module
  # here. It must implement the Elasticsearch.API behaviour.
  api: Elasticsearch.API.HTTP,

  # Customize the library used for JSON encoding/decoding.
  json_library: Poison, # or Jason

  # You should configure each index which you maintain in Elasticsearch here.
  # This configuration will be read by the `mix elasticsearch.build` task,
  # described below.
  indexes: %{
    # This is the base name of the Elasticsearch index. Each index will be
    # built with a timestamp included in the name, like "posts-5902341238".
    # It will then be aliased to "posts" for easy querying.
    posts: %{
      # This file describes the mappings and settings for your index. It will
      # be posted as-is to Elasticsearch when you create your index, and
      # therefore allows all the settings you could post directly.
      settings: "priv/elasticsearch/posts.json",

      # This store module must implement a store behaviour. It will be used to
      # fetch data for each source in each indexes' `sources` list, below:
      store: MyApp.ElasticsearchStore,

      # This is the list of data sources that should be used to populate this
      # index. The `:store` module above will be passed each one of these
      # sources for fetching.
      #
      # Each piece of data that is returned by the store must implement the
      # Elasticsearch.Document protocol.
      sources: [MyApp.Post],

      # When indexing data using the `mix elasticsearch.build` task,
      # control the data ingestion rate by raising or lowering the number
      # of items to send in each bulk request.
      bulk_page_size: 5000,

      # Likewise, wait a given period between posting pages to give
      # Elasticsearch time to catch up.
      bulk_wait_interval: 15_000 # 15 seconds
    }
  }

Specifying HTTPoison Options

config :my_app, MyApp.ElasticsearchCluster,
  default_options: [
    timeout: 5_000,
    recv_timeout: 5_000,
    hackney: [pool: :pool_name]
  ]

Protocols and Behaviours

Elasticsearch.Store

Your app must provide a Store module, which will fetch data to upload to Elasticsearch. This module must implement the Elasticsearch.Store behaviour.

The example below uses Ecto, but you can implement the behaviour on top of any persistence layer.

defmodule MyApp.ElasticsearchStore do
  @behaviour Elasticsearch.Store

  import Ecto.Query

  alias MyApp.Repo

  @impl true
  def stream(schema) do
    Repo.stream(schema)
  end

  @impl true
  def transaction(fun) do
    {:ok, result} = Repo.transaction(fun, timeout: :infinity)
    result
  end
end

Elasticsearch.Document

Each result returned by your store must implement the Elasticsearch.Document protocol.

defimpl Elasticsearch.Document, for: MyApp.Post do
  def id(post), do: post.id
  def routing(_), do: false
  def encode(post) do
    %{
      title: post.title,
      author: post.author
    }
  end
end

Elasticsearch.API

You can plug in a different module to make API requests, as long as it implements the Elasticsearch.API behaviour.

This can be used in test mode, for example:

# config/test.exs
config :my_app, MyApp.ElasticsearchCluster,
  api: MyApp.ElasticsearchMock

Your mock can then stub requests and responses from Elasticsearch.

defmodule MyApp.ElasticsearchMock do
  @behaviour Elasticsearch.API

  @impl true
  def request(_config, :get, "/posts/1", _data, _opts) do
    {:ok, %HTTPoison.Response{
      status_code: 404,
      body: %{
        "status" => "not_found"
      }
    }}
  end
end

Elasticsearch.API.AWS

As AWS does not provide credentials' based http authentication, you can use the Elasticsearch.API.AWS module if you want to use AWS Elasticsearch Service with AWS Signature V4 signed HTTP connections.

To use this, just add sigaws to your dependencies and add this to your configuration:

# Add to deps 
def deps do
  [          
    # ...
    {:sigaws, ">= 0.0.0"}
  ]
end

# config/prod.exs
config :my_app, MyApp.ElasticsearchCluster,
  api: Elasticsearch.API.AWS,
  default_options: [
    aws: [
      region: "us-east-1",
      service: "es",
      access_key: "aws_access_key_id",
      secret: "aws_secret_access_key"
    ]
  ]

Indexing

Bulk

Use the mix elasticsearch.build task to build indexes using a zero-downtime, hot-swap technique with Elasticsearch aliases.

# This will read the `indexes[posts]` configuration seen above, to build
# an index, `posts-123123123`, which will then be aliased to `posts`.
$ mix elasticsearch.build posts --cluster MyApp.ElasticsearchCluster

See the docs on Mix.Tasks.Elasticsearch.Build and Elasticsearch.Index for more details.

Individual Documents

Use Elasticsearch.put_document/3 to upload a document to a particular index.

# MyApp.Post must implement Elasticsearch.Document
Elasticsearch.put_document(MyApp.ElasticsearchCluster, %MyApp.Post{}, "index-name")

To remove documents, use Elasticsearch.delete_document/3:

Elasticsearch.delete_document(MyApp.ElasticsearchCluster, %MyApp.Post{}, "index-name")

Querying

You can query Elasticsearch the post/3 function:

# Raw query
Elasticsearch.post(MyApp.ElasticsearchCluster, "/posts/_doc/_search", '{"query": {"match_all": {}}}')

# Using a map
Elasticsearch.post(MyApp.ElasticsearchCluster, "/posts/_doc/_search", %{"query" => %{"match_all" => %{}}})

See the official Elasticsearch documentation for how to write queries.

Dev Tools

This package provides two utilities for developing with Elasticsearch:

  • mix elasticsearch.install: A mix task to install Elasticsearch and Kibana to a folder of your choosing.

  • Elasticsearch.Executable. Use this to start and stop Elasticsearch as part of your supervision tree.

    children = [
      worker(Elasticsearch.Executable, [
        "Elasticsearch",
        "./vendor/elasticsearch/bin/elasticsearch", # assuming elasticsearch is in your vendor/ dir
        9200
      ], id: :elasticsearch),
      worker(Elasticsearch.Executable, [
        "Kibana",
        "./vendor/kibana/bin/kibana", # assuming kibana is in your vendor/ dir
        5601
      ], id: :kibana)
    ]
    

Elasticsearch 5.x Support

As of version 0.3.0 of this client library, multiple document types are not supported, because support for these was removed in Elasticsearch 6.x. You can still use this library with Elasticsearch 5.x, but you must design your indexes in the Elasticsearch 6.x style.

Read more about this in Elasticsearch's guide, "Removal of Mapping Types".

Documentation

Hex Documentation

Run mix docs to generate local documentation.

Contributing

To contribute code to this project, you'll need to:

  1. Fork the repo
  2. Clone your fork
  3. Run bin/setup
  4. Create a branch
  5. Commit your changes
  6. Open a PR
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].