use correct document type

This commit is contained in:
Liam P. White 2019-08-28 21:18:40 -04:00
parent 047e02c9ba
commit 7bda48cbfa
2 changed files with 6 additions and 4 deletions

View file

@ -2,6 +2,7 @@ defmodule Philomena.Elasticsearch do
defmacro __using__(opts) do defmacro __using__(opts) do
definition = Keyword.fetch!(opts, :definition) definition = Keyword.fetch!(opts, :definition)
index_name = Keyword.fetch!(opts, :index_name) index_name = Keyword.fetch!(opts, :index_name)
doc_type = Keyword.fetch!(opts, :doc_type)
elastic_url = Application.get_env(:philomena, :elasticsearch_url) elastic_url = Application.get_env(:philomena, :elasticsearch_url)
@ -24,7 +25,7 @@ defmodule Philomena.Elasticsearch do
def index_document(doc) do def index_document(doc) do
data = unquote(definition).as_json(doc) data = unquote(definition).as_json(doc)
Elastix.Document.index(unquote(elastic_url), unquote(index_name), ["_doc"], data.id, data) Elastix.Document.index(unquote(elastic_url), unquote(index_name), [unquote(doc_type)], data.id, data)
end end
def reindex(ecto_query, batch_size \\ 1000) do def reindex(ecto_query, batch_size \\ 1000) do
@ -51,7 +52,7 @@ defmodule Philomena.Elasticsearch do
doc = unquote(definition).as_json(m) doc = unquote(definition).as_json(m)
[ [
%{index: %{_index: unquote(index_name), _type: "_doc", _id: doc.id}}, %{index: %{_index: unquote(index_name), _type: unquote(doc_type), _id: doc.id}},
doc doc
] ]
end) end)
@ -79,7 +80,7 @@ defmodule Philomena.Elasticsearch do
Elastix.Search.search( Elastix.Search.search(
unquote(elastic_url), unquote(elastic_url),
unquote(index_name), unquote(index_name),
["_doc"], [unquote(doc_type)],
elastic_query elastic_query
) )

View file

@ -3,7 +3,8 @@ defmodule Philomena.Images.Image do
use Philomena.Elasticsearch, use Philomena.Elasticsearch,
definition: Philomena.Images.Elasticsearch, definition: Philomena.Images.Elasticsearch,
index_name: "images" index_name: "images",
doc_type: "image"
import Ecto.Changeset import Ecto.Changeset