Upgrading from 0.4.x to 0.5.x

Changes

BREAKING: routing function is now required to be specified in the Elasticsearch.Document protocol. You may specify it to return false to use default routing (document id).

The routing/_routing meta-field is used to force a document to be hashed to a particular shard which is required for join field datatypes but also used to gain more control over which shard your documents are routed to.

BREAKING: The Elasticsearch.Store behaviour has been changed to use streams instead of limit/offset. This is more performant on SQL databases.

BREAKING: Index.hot_swap/3 was refactored to take only 2 arguments, the cluster and the index to be built. This makes it easier to call.

Feature: This library now better supports Distillery for deployment. See the Distillery guide for details.

How to Update Your App

Update your Hex dependency from 0.4.x to 0.5.x:

  {:elasticsearch, "~> 0.5.0"}

Add a routing/1 function to your Elasticsearch.Document implementations.

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

# AFTER (using default routing)
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

# AFTER (using routing)
defimpl Elasticsearch.Document, for: MyApp.Post do
  def id(post), do: post.id
  def routing(post), do: post.account_id
  def encode(post) do
    %{
      title: post.title,
      author: post.author
    }
  end
end

Change your Elasticsearch.Store module to use streams. Here's an example if you're using Ecto.

# BEFORE
def MyApp.ElasticsearchStore do
  @behaviour Elasticsearch.Store

  import Ecto.Query

  alias MyApp.Repo

  @impl true
  def load(schema, offset, limit) do
    schema
    |> offset(^offset)
    |> limit(^limit)
    |> Repo.all()
  end
end

# AFTER
defmodule MyApp.ElasticsearchStore do
  @behaviour Elasticsearch.Store

  alias MyApp.Repo

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

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