From 7bda48cbfa086a6466d0151798450de0f018e95b Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Wed, 28 Aug 2019 21:18:40 -0400 Subject: [PATCH] use correct document type --- lib/philomena/elasticsearch.ex | 7 ++++--- lib/philomena/images/image.ex | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/philomena/elasticsearch.ex b/lib/philomena/elasticsearch.ex index f8e39a96..0dc841f3 100644 --- a/lib/philomena/elasticsearch.ex +++ b/lib/philomena/elasticsearch.ex @@ -2,6 +2,7 @@ defmodule Philomena.Elasticsearch do defmacro __using__(opts) do definition = Keyword.fetch!(opts, :definition) index_name = Keyword.fetch!(opts, :index_name) + doc_type = Keyword.fetch!(opts, :doc_type) elastic_url = Application.get_env(:philomena, :elasticsearch_url) @@ -24,7 +25,7 @@ defmodule Philomena.Elasticsearch do def index_document(doc) do 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 def reindex(ecto_query, batch_size \\ 1000) do @@ -51,7 +52,7 @@ defmodule Philomena.Elasticsearch do 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 ] end) @@ -79,7 +80,7 @@ defmodule Philomena.Elasticsearch do Elastix.Search.search( unquote(elastic_url), unquote(index_name), - ["_doc"], + [unquote(doc_type)], elastic_query ) diff --git a/lib/philomena/images/image.ex b/lib/philomena/images/image.ex index 85b8406c..eff0db15 100644 --- a/lib/philomena/images/image.ex +++ b/lib/philomena/images/image.ex @@ -3,7 +3,8 @@ defmodule Philomena.Images.Image do use Philomena.Elasticsearch, definition: Philomena.Images.Elasticsearch, - index_name: "images" + index_name: "images", + doc_type: "image" import Ecto.Changeset