Skip to content

Latest commit

 

History

History
74 lines (53 loc) · 2.38 KB

README.md

File metadata and controls

74 lines (53 loc) · 2.38 KB

ExlasticSearch

Module Version Hex Docs Total Download License Last Updated

An Elasticsearch DSLs for mapping Ecto models to Elasticsearch mappings, along with Elixir friendly query wrappers, response formatting and the like.

Installation

def deps do
  [
    {:exlasticsearch, "~> 2.2.3"}
  ]
end

Docs are available on hex

Usage

You can pair an ExlasticSearch.Model with an existing schema like:

defmodule MySchema do
  # ...
  use ExlasticSearch.Model

  indexes :my_index do
    settings Application.get_env(:some, :settings)

    mapping :field
    mapping :other_field, type: :keyword # ecto derived defaults can be overridden
  end
end

You can then construct queries like so:

MySchema.search_query()
|> must(match(field, value))
|> should(match_phrase(field, value, opts))
|> filter(term(filter_field, value))

A repo model like Ecto is provided, so a with ability to do most restful operations on records, in addition to calling search APIs with the query structs above.

If additional data needs to be fetched or formatted prior to insertion into elastic, the ExlasticSearch.Indexable protocol can be implemented to do that for you. A default implementation can also be generated as part of using the ExlasticSearch.Model macro.

Configuration

This library requires Elastix, an Elixir Elasticsearch HTTP client. So refer to it for any HTTP related configuration. In addition, there are the following configuration options:

config :exlasticsearch, :type_inference, ExlasticSearch.TypeInference

config :exlasticsearch, ExlasticSearch.Repo,
  url: "http://localhost:9200"

Copyright and License

Copyright (c) 2018 Frame.io

This software is released under the MIT License.