All Projects → ikeikeikeike → Esx

ikeikeikeike / Esx

Licence: mit
A client for the Elasticsearch with Ecto, written in Elixir

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Esx

Complete Guide To Elasticsearch
Contains all of the queries used within the Complete Guide to Elasticsearch course.
Stars: ✭ 829 (+3216%)
Mutual labels:  elasticsearch
Odsc 2020 nlp
Repository for ODSC talk related to Deep Learning NLP
Stars: ✭ 20 (-20%)
Mutual labels:  elasticsearch
Query
Query adds tools to aid the use of Ecto in web settings.
Stars: ✭ 23 (-8%)
Mutual labels:  ecto
Scalable Image Matching
This is a image matching system for scalable and efficient matching of images from a large database. The basic idea is to compute perceptural hash value for each image and compare the similarity based on the pHash computed. Searching are scalable with the elasticsearch as the backend database.
Stars: ✭ 17 (-32%)
Mutual labels:  elasticsearch
Elasticsearchdemo
ElasticSearch+Springboot的例子,对本机的文本等文件进行全文检索
Stars: ✭ 18 (-28%)
Mutual labels:  elasticsearch
Kafka Connect Elasticsearch Source
Kafka Connect Elasticsearch Source
Stars: ✭ 22 (-12%)
Mutual labels:  elasticsearch
Datastream.io
An open-source framework for real-time anomaly detection using Python, ElasticSearch and Kibana
Stars: ✭ 814 (+3156%)
Mutual labels:  elasticsearch
Docker Fscrawler
Dockerfile for https://github.com/dadoonet/fscrawler
Stars: ✭ 24 (-4%)
Mutual labels:  elasticsearch
Hugo Elasticsearch
Generate Elasticsearch indexes for Hugo static sites by parsing front matter
Stars: ✭ 19 (-24%)
Mutual labels:  elasticsearch
Search Spring Boot Starter
ElasticSearch封装基于ES版本6.4.2,极大简化了ES操作难度
Stars: ✭ 23 (-8%)
Mutual labels:  elasticsearch
Great Big Example Application
A full-stack example app built with JHipster, Spring Boot, Kotlin, Angular 4, ngrx, and Webpack
Stars: ✭ 899 (+3496%)
Mutual labels:  elasticsearch
Elasticsearch Query Builder
Build query for an ElasticSearch client using a fluent interface
Stars: ✭ 18 (-28%)
Mutual labels:  elasticsearch
Elasticsearch Readonlyrest Plugin
Free Elasticsearch security plugin and Kibana security plugin: super-easy Kibana multi-tenancy, Encryption, Authentication, Authorization, Auditing
Stars: ✭ 917 (+3568%)
Mutual labels:  elasticsearch
Heroic
The Heroic Time Series Database
Stars: ✭ 836 (+3244%)
Mutual labels:  elasticsearch
Kafka Connect Elastic Sink
Kafka connect Elastic sink connector, with just in time index/delete behaviour.
Stars: ✭ 23 (-8%)
Mutual labels:  elasticsearch
Szt Bigdata
深圳地铁大数据客流分析系统🚇🚄🌟
Stars: ✭ 826 (+3204%)
Mutual labels:  elasticsearch
Fscrawler
Elasticsearch File System Crawler (FS Crawler)
Stars: ✭ 906 (+3524%)
Mutual labels:  elasticsearch
Milog
Milog 是一基于 Ruby on Rails 的个人博客网站
Stars: ✭ 24 (-4%)
Mutual labels:  elasticsearch
Elastic Muto
Easy expressive search queries for Elasticsearch
Stars: ✭ 24 (-4%)
Mutual labels:  elasticsearch
Docker Kibana
Kibana Docker image including search-guard
Stars: ✭ 22 (-12%)
Mutual labels:  elasticsearch

ESx

Build Status Ebert Hex version Inline docs Lisence

A client for the Elasticsearch with Ecto, written in Elixir

Installation

If available in Hex, the package can be installed as:

  1. Add esx to your list of dependencies in mix.exs:
def deps do
  [{:esx, "~> x.x.x"}]
end
  1. Ensure esx is started before your application:
def application do
  [applications: [:esx]]
end

hexdocs: https://hexdocs.pm/esx

Configuration

This is configuration that if you've have multiple Elasticsearch's Endpoint which's another one.

First, that configuration is defined with ESx.Model.Base into your project. It's like Ecto's Repo.

defmodule MyApp.ESx do
  use ESx.Model.Base, app: :my_app
end

And so that there's MyApp.ESx configuration for Mix.config below.

config :my_app, MyApp.ESx,
  scheme: "http",
  host: "example.com",
  port: 9200

Definition for all of configuration.

config :my_app, MyApp.ESx,
  repo: MyApp.Repo,                        # Optional, which defines Ecto for connecting database.
  protocol: "http",                        # or: scheme: "http"
  user: "yourname", password: "yourpass",  # or: userinfo: "yourname:yourpass"
  host: "127.0.0.1",
  port: 9200,
  path: "path-to-endpoint"

Definition for Analysis.

DSL

defmodule MyApp.Blog do
  use ESx.Schema

  index_name    "blog"  # Optional
  document_type "blog"  # Optional

  mapping _all: [enabled: false], _ttl: [enabled: true, default: "180d"] do
    indexes :title, type: "string"
    indexes :content, type: "string"
    indexes :publish, type: "boolean"
  end

  settings number_of_shards: 10, number_of_replicas: 2 do
    analysis do
      filter :ja_posfilter,
        type: "kuromoji_neologd_part_of_speech",
        stoptags: ["助詞-格助詞-一般", "助詞-終助詞"]
      tokenizer :ja_tokenizer,
        type: "kuromoji_neologd_tokenizer"
      analyzer :default,
        type: "custom", tokenizer: "ja_tokenizer",
        filter: ["kuromoji_neologd_baseform", "ja_posfilter", "cjk_width"]
    end
  end

end

Setting by keywords lists

defmodule Something.Schema do
  use ESx.Schema

  mapping [
    _ttl: [
      enabled: true,
      default: "180d"
    ],
    _all: [
      enabled: false
    ],
    properties: [
      title: [
        type: "string",
        analyzer: "ja_analyzer"
      ],
      publish: [
        type: "boolean"
      ],
      content: [
        type: "string",
        analyzer: "ja_analyzer"
      ]
    ]
  ]

  settings [
    number_of_shards:   1,
    number_of_replicas: 0,
    analysis: [
      analyzer: [
        ja_analyzer: [
          type:      "custom",
          tokenizer: "kuromoji_neologd_tokenizer",
          filter:    ["kuromoji_neologd_baseform", "cjk_width"],
        ]
      ]
    ]
  ]

end

Definition for updating record via such as a Model.

defmodule MyApp.Blog do
  use ESx.Schema

  defstruct [:id, :title, :content, :publish]

  mapping do
    indexes :title, type: "string"
    indexes :content, type: "string"
    indexes :publish, type: "boolean"
  end
end

With Ecto's Model

defmodule MyApp.Blog do
  use MyApp.Web, :model
  use ESx.Schema

  schema "blogs" do
    field :title, :string
    field :content, :string
    field :publish, :boolean

    timestamps
  end

  mapping do
    indexes :title, type: "string"
    indexes :content, type: "string"
    indexes :publish, type: "boolean"
  end
Indexing Data

The data's elements which sends to Elasticsearch is able to customize that will make it, this way is the same as Ecto.

defmodule MyApp.Blog do
  @derive {Poison.Encoder, only: [:title, :publish]}
  schema "blogs" do
    field :title, :string
    field :content, :string
    field :publish, :boolean

    timestamps
  end
end

When Ecto's Schema and ESx's mapping have defferent fields or for customization more, defining function as_indexed_json will make it in order to send relational data to Elasticsearch, too. Commonly it called via MyApp.ESx.index_document, MyApp.ESx.update_document.

defmodule MyApp.Blog do
  def as_indexed_json(struct, opts) do
    all_of_defined_data = super struct, opts
    ...
    ...

    some_of_custmized_data
  end
end

By default will send all of defined mapping's fields to Elasticsearch.

API Docs

Transport

ESx.Transport and MyApp.ESx will connect to multipe elasticsearch automatically if builded cluster systems on your environment.

iex(1)> MyApp.ESx.transport # Load configuration to ESX.Transport this is required.
iex(2)> ESx.Transport.conn  # Sniffing cluster system and choose random Elasticsearch connection

01:10:26.694 [debug] curl -X GET 'http://127.0.0.1:9200/_nodes/http'  # Run sniffing

%ESx.Transport.Connection{client: HTTPoison, dead: false, # chose one of cluster connection.
 dead_since: 1492099826, failures: 0,
 pidname: :"RWxpeGlyLkVTeC5UcmFuc3BvcnQuQ29ubmVjdGlvbl9odHRwOi8vMTI3LjAuMC4xOjkyMDI=",
 resurrect_timeout: 60, url: "http://127.0.0.1:9202"}

iex(2)> ESx.Transport.Connection.conns  # Below is all of cluster connections.
[%ESx.Transport.Connection{client: HTTPoison, dead: false,
  dead_since: 1492099826, failures: 0,
  pidname: :"RWxpeGlyLkVTeC5UcmFuc3BvcnQuQ29ubmVjdGlvbl9odHRwOi8vMTI3LjAuMC4xOjkyMDE=",
  resurrect_timeout: 60, url: "http://127.0.0.1:9201"},
 %ESx.Transport.Connection{client: HTTPoison, dead: false,
  dead_since: 1492099826, failures: 0,
  pidname: :"RWxpeGlyLkVTeC5UcmFuc3BvcnQuQ29ubmVjdGlvbl9odHRwOi8vMTI3LjAuMC4xOjkyMDI=",
  resurrect_timeout: 60, url: "http://127.0.0.1:9202"},
 %ESx.Transport.Connection{client: HTTPoison, dead: false,
  dead_since: 1492099826, failures: 0,
  pidname: :"RWxpeGlyLkVTeC5UcmFuc3BvcnQuQ29ubmVjdGlvbl9odHRwOi8vMTI3LjAuMC4xOjkyMDA=",
  resurrect_timeout: 60, url: "http://127.0.0.1:9200"}]

Usage

Indexing

MyApp.ESx.reindex, MyApp.Blog
MyApp.ESx.create_index, MyApp.Blog
MyApp.ESx.delete_index, MyApp.Blog
MyApp.ESx.index_exists?, MyApp.Blog
MyApp.ESx.refresh_index, MyApp.Blog

ES Document

MyApp.ESx.import, MyApp.Blog
MyApp.ESx.index_document, %MyApp.Blog{id: 1, title: "egg"}
MyApp.ESx.delete_document, %MyApp.Blog{id: 1, title: "ham"}

Search & Response

MyApp.ESx.search, MyApp.Blog, %{query: %{match: %{title: "foo"}}}
response =
  MyApp.Blog
  |> MyApp.ESx.search(%{query: %{match: %{title: "foo"}}})
  |> MyApp.ESx.results

IO.inspect Enum.map(response, fn r ->
  r["_source"]["title"]
end)
# ["foo", "egg", "some"]
With Phoenix's Ecto
response =
  MyApp.Blog
  |> MyApp.ESx.search(%{query: %{match: %{title: "foo"}}})
  |> MyApp.ESx.records

IO.inspect Enum.each(response, fn r ->
  r.title
end)
# ["foo", "egg", "some"]
API Docs
Pagination

github.com/ikeikeikeike/scrivener_esx

page =
  MyApp.Blog
  |> MyApp.ESx.search(%{query: %{match: %{title: "foo"}}})
  |> MyApp.ESx.paginate(page: 2, page_size: 5)

Low-level APIs

Configuration

config :esx, ESx.Model,
  url: "http://example.com:9200"

There're Low-level APIs in ESx.API and ESx.API.Indices.

ts = ESx.Transport.transport trace: true  # or: ts = MyApp.ESx.transport

ESx.API.search ts, %{index: "your_app", body: %{query: %{}}}

ESx.API.Indices.delete ts, %{index: "your_app"}
API Docs

Testing

Download elasticsearch and build cluster

$ ./test/build.sh

run mix test

$ mix test

Probably won't make it.

  • Search DSL
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].