diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index c192260..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,69 +0,0 @@ -# Elixir CircleCI 2.0 configuration file -# -# Check https://circleci.com/docs/2.0/language-elixir/ for more details -version: 2 -shared: &shared - working_directory: ~/repo - steps: - - checkout - - - run: mix local.hex --force - - run: mix local.rebar --force - - - run: mix deps.get - - run: MIX_ENV=test mix compile - - # Wait for Elasticsearch - - run: - command: | - while ! curl -sS --fail http://localhost:9200 > /dev/null 2>&1; do - sleep 1 - done - - - run: MIX_ENV=test mix test - -jobs: - "elasticsearch-5.6": - <<: *shared - docker: - - image: elixir:latest - - image: docker.elastic.co/elasticsearch/elasticsearch:5.6.2 - environment: - - discovery.type=single-node - - xpack.security.enabled=false - - "elasticsearch-5.5": - <<: *shared - docker: - - image: elixir:latest - - image: docker.elastic.co/elasticsearch/elasticsearch:5.5.3 - environment: - - discovery.type=single-node - - xpack.security.enabled=false - - "elasticsearch-5.4": - <<: *shared - docker: - - image: elixir:latest - - image: docker.elastic.co/elasticsearch/elasticsearch:5.4.3 - environment: - - discovery.type=single-node - - xpack.security.enabled=false - - "elasticsearch-5.3": - <<: *shared - docker: - - image: elixir:latest - - image: docker.elastic.co/elasticsearch/elasticsearch:5.3.3 - environment: - - xpack.security.enabled=false - - -workflows: - version: 2 - build: - jobs: - - "elasticsearch-5.6" - - "elasticsearch-5.5" - - "elasticsearch-5.4" - - "elasticsearch-5.3" diff --git a/.gitignore b/.gitignore index ca84141..209be86 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,6 @@ elastix-*.tar # Misc. tags + +.idea/ +elastix.iml \ No newline at end of file diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..8149db2 --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +elixir 1.18.4-otp-28 +erlang 28.1.1 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c29b25c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -sudo: false -dist: trusty -language: elixir -elixir: - - 1.6.1 - - 1.7.4 - - 1.8.2 - - 1.9.4 -services: - - elasticsearch -before_script: - - 'echo "path.repo: /tmp" | sudo tee -a /etc/elasticsearch/elasticsearch.yml' - - 'sudo service elasticsearch restart' - - mix credo --strict -script: "mix test" -notifications: - email: werbitzky@gmail.com diff --git a/config/config.exs b/config/config.exs index c39c04f..d9bf889 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,6 +1,6 @@ # This file is responsible for configuring your application # and its dependencies with the aid of the Mix.Config module. -use Mix.Config +import Config # This configuration is loaded before any dependency and is restricted # to this project. If another project depends on this project, this diff --git a/config/dev.exs b/config/dev.exs index e5f95aa..422fe80 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -1,4 +1,4 @@ -use Mix.Config +import Config config :mix_test_watch, tasks: [ diff --git a/config/test.exs b/config/test.exs index 9cb3ef2..88be3ed 100644 --- a/config/test.exs +++ b/config/test.exs @@ -1,4 +1,4 @@ -use Mix.Config +import Config config :elastix, test_url: "http://127.0.0.1:9200", diff --git a/lib/elastix/bulk.ex b/lib/elastix/bulk.ex index 7292d05..16da75b 100644 --- a/lib/elastix/bulk.ex +++ b/lib/elastix/bulk.ex @@ -29,7 +29,7 @@ defmodule Elastix.Bulk do path = Keyword.get(options, :index) - |> make_path(Keyword.get(options, :type), query_params) + |> make_path(query_params) httpoison_options = Keyword.get(options, :httpoison_options, []) @@ -55,8 +55,12 @@ defmodule Elastix.Bulk do httpoison_options = Keyword.get(options, :httpoison_options, []) (elastic_url <> - make_path(Keyword.get(options, :index), Keyword.get(options, :type), query_params)) - |> HTTP.put(Enum.map(lines, fn line -> JSON.encode!(line) <> "\n" end), [], httpoison_options) + make_path(Keyword.get(options, :index), query_params)) + |> HTTP.put( + Enum.map(lines, fn line -> JSON.encode!(line) <> "\n" end), + [], + httpoison_options + ) end @doc """ @@ -70,17 +74,16 @@ defmodule Elastix.Bulk do query_params :: Keyword.t() ) :: HTTP.resp() def post_raw(elastic_url, raw_data, options \\ [], query_params \\ []) do - httpoison_options = Keyword.get(options, :httpoison_options, []) (elastic_url <> - make_path(Keyword.get(options, :index), Keyword.get(options, :type), query_params)) + make_path(Keyword.get(options, :index), query_params)) |> HTTP.put(raw_data, [], httpoison_options) end @doc false - def make_path(index_name, type_name, query_params) do - path = make_base_path(index_name, type_name) + def make_path(index_name, query_params) do + path = make_base_path(index_name) case query_params do [] -> path @@ -88,7 +91,6 @@ defmodule Elastix.Bulk do end end - defp make_base_path(nil, nil), do: "/_bulk" - defp make_base_path(index_name, nil), do: "/#{index_name}/_bulk" - defp make_base_path(index_name, type_name), do: "/#{index_name}/#{type_name}/_bulk" + defp make_base_path(nil), do: "/_bulk" + defp make_base_path(index_name), do: "/#{index_name}/_bulk" end diff --git a/lib/elastix/document.ex b/lib/elastix/document.ex index 9a8c5d1..b95df35 100644 --- a/lib/elastix/document.ex +++ b/lib/elastix/document.ex @@ -76,12 +76,11 @@ defmodule Elastix.Document do elastic_url :: String.t(), query :: map, index :: String.t(), - type :: String.t(), query_params :: Keyword.t() ) :: HTTP.resp() - def mget(elastic_url, query, index_name \\ nil, type_name \\ nil, query_params \\ []) do + def mget(elastic_url, query, index_name \\ nil, query_params \\ []) do path = - [index_name, type_name] + [index_name] |> Enum.reject(&is_nil/1) |> Enum.join("/") @@ -140,14 +139,18 @@ defmodule Elastix.Document do @spec update( elastic_url :: String.t(), index :: String.t(), - type :: String.t(), id :: String.t(), data :: map, query_params :: Keyword.t() ) :: HTTP.resp() - def update(elastic_url, index_name, type_name, id, data, query_params \\ []) do + def update(elastic_url, index_name, id, data, query_params \\ []) do + # ES 7.x+ removed types from update URL + path = + "/#{index_name}/_update/#{id}" + |> HTTP.append_query_string(query_params) + elastic_url - |> prepare_url(make_path(index_name, type_name, query_params, id, "_update")) + |> prepare_url(path) |> HTTP.post(JSON.encode!(data)) end @@ -199,14 +202,20 @@ defmodule Elastix.Document do end @doc false - def make_path(index_name, type_name, query_params) do - "/#{index_name}/#{type_name}" + def make_path(index_name, _type_name, query_params) do + # ES 7.x+ removed types from document URLs, always use _doc + "/#{index_name}/_doc" |> HTTP.append_query_string(query_params) end @doc false - def make_path(index_name, type_name, query_params, id, suffix \\ nil) do - "/#{index_name}/#{type_name}/#{id}/#{suffix}" - |> HTTP.append_query_string(query_params) + def make_path(index_name, _type_name, query_params, id, suffix \\ nil) do + # ES 7.x+ removed types from document URLs, always use _doc + path = + if suffix, + do: "/#{index_name}/_doc/#{id}/#{suffix}", + else: "/#{index_name}/_doc/#{id}" + + HTTP.append_query_string(path, query_params) end end diff --git a/lib/elastix/mapping.ex b/lib/elastix/mapping.ex index aa24ad6..54a5a15 100644 --- a/lib/elastix/mapping.ex +++ b/lib/elastix/mapping.ex @@ -108,11 +108,11 @@ defmodule Elastix.Mapping do do: get_all_with_type(elastic_url, [type_name], query_params) @doc false - def make_path(index_names, type_names, query_params) do + def make_path(index_names, _type_names, query_params) do + # ES 7.x+ removed types from mapping URLs index_names = Enum.join(index_names, ",") - type_names = Enum.join(type_names, ",") - path = "/#{index_names}/_mapping/#{type_names}" + path = "/#{index_names}/_mapping" case query_params do [] -> path @@ -131,10 +131,9 @@ defmodule Elastix.Mapping do end @doc false - def make_all_path(type_names, query_params) do - type_names = Enum.join(type_names, ",") - - path = "/_mapping/#{type_names}" + def make_all_path(_type_names, query_params) do + # ES 7.x+ removed types from mapping URLs + path = "/_mapping" case query_params do [] -> path diff --git a/lib/elastix/search.ex b/lib/elastix/search.ex index 7b22260..a994383 100644 --- a/lib/elastix/search.ex +++ b/lib/elastix/search.ex @@ -117,16 +117,10 @@ defmodule Elastix.Search do end @doc false - def make_path(index, types, query_params, api_type \\ "_search") do + def make_path(index, _types, query_params, api_type \\ "_search") do + # ES 7.x+ removed types from search URLs path_root = "/#{index}" - - path = - case types do - [] -> path_root - _ -> path_root <> "/" <> Enum.join(types, ",") - end - - full_path = "#{path}/#{api_type}" + full_path = "#{path_root}/#{api_type}" case query_params do [] -> full_path diff --git a/lib/elastix/snapshot/repository.ex b/lib/elastix/snapshot/repository.ex index 2280e28..b8a0cb4 100644 --- a/lib/elastix/snapshot/repository.ex +++ b/lib/elastix/snapshot/repository.ex @@ -12,7 +12,7 @@ defmodule Elastix.Snapshot.Repository do Registers a repository. """ @spec register(String.t(), String.t(), Map.t(), [tuple()]) :: - {:ok, %HTTPoison.Response{}} + {:ok, HTTPoison.Response.t({})} def register(elastic_url, repo_name, data, query_params \\ []) do elastic_url |> prepare_url(make_path(repo_name, query_params)) @@ -22,7 +22,7 @@ defmodule Elastix.Snapshot.Repository do @doc """ Verifies a registered but unverified repository. """ - @spec verify(String.t(), String.t()) :: {:ok, %HTTPoison.Response{}} + @spec verify(String.t(), String.t()) :: {:ok, HTTPoison.Response.t({})} def verify(elastic_url, repo_name) do elastic_url |> prepare_url([make_path(repo_name), "_verify"]) @@ -33,7 +33,7 @@ defmodule Elastix.Snapshot.Repository do If repo_name specified, will retrieve information about a registered repository. Otherwise, will retrieve information about all repositories. """ - @spec get(String.t(), String.t()) :: {:ok, %HTTPoison.Response{}} + @spec get(String.t(), String.t()) :: {:ok, HTTPoison.Response.t({})} def get(elastic_url, repo_name \\ "_all") do elastic_url |> prepare_url(make_path(repo_name)) @@ -43,7 +43,7 @@ defmodule Elastix.Snapshot.Repository do @doc """ Removes the reference to the location where the snapshots are stored. """ - @spec delete(String.t(), String.t()) :: {:ok, %HTTPoison.Response{}} + @spec delete(String.t(), String.t()) :: {:ok, HTTPoison.Response.t({})} def delete(elastic_url, repo_name) do elastic_url |> prepare_url(make_path(repo_name)) diff --git a/lib/elastix/snapshot/snapshot.ex b/lib/elastix/snapshot/snapshot.ex index 1da3ebc..d059688 100644 --- a/lib/elastix/snapshot/snapshot.ex +++ b/lib/elastix/snapshot/snapshot.ex @@ -12,8 +12,15 @@ defmodule Elastix.Snapshot.Snapshot do Creates a snapshot. """ @spec create(String.t(), String.t(), String.t(), Map.t(), [tuple()], Keyword.t()) :: - {:ok, %HTTPoison.Response{}} - def create(elastic_url, repo_name, snapshot_name, data \\ %{}, query_params \\ [], options \\ []) do + {:ok, HTTPoison.Response.t()} + def create( + elastic_url, + repo_name, + snapshot_name, + data \\ %{}, + query_params \\ [], + options \\ [] + ) do elastic_url |> prepare_url(make_path(repo_name, snapshot_name, query_params)) |> HTTP.put(JSON.encode!(data), [], _make_httpoison_options(options)) @@ -23,7 +30,7 @@ defmodule Elastix.Snapshot.Snapshot do Restores a previously created snapshot. """ @spec restore(String.t(), String.t(), String.t(), Map.t(), Keyword.t()) :: - {:ok, %HTTPoison.Response{}} + {:ok, HTTPoison.Response.t()} def restore(elastic_url, repo_name, snapshot_name, data \\ %{}, options \\ []) do elastic_url |> prepare_url([make_path(repo_name, snapshot_name), "_restore"]) @@ -35,7 +42,8 @@ defmodule Elastix.Snapshot.Snapshot do snapsot. If repo_name is specified, will retrieve the status of all snapshots in that repository. Otherwise, will retrieve the status of all snapshots. """ - @spec status(String.t(), String.t(), String.t(), Keyword.t()) :: {:ok, %HTTPoison.Response{}} + @spec status(String.t(), String.t(), String.t(), Keyword.t()) :: + {:ok, HTTPoison.Response.t()} def status(elastic_url, repo_name \\ "", snapshot_name \\ "", options \\ []) do elastic_url |> prepare_url([make_path(repo_name, snapshot_name), "_status"]) @@ -48,7 +56,8 @@ defmodule Elastix.Snapshot.Snapshot do all snapshots in that repository. Otherwise, will retrieve information about all snapshots. """ - @spec get(String.t(), String.t(), String.t(), Keyword.t()) :: {:ok, %HTTPoison.Response{}} + @spec get(String.t(), String.t(), String.t(), Keyword.t()) :: + {:ok, HTTPoison.Response.t()} def get(elastic_url, repo_name \\ "", snapshot_name \\ "_all", options \\ []) do elastic_url |> prepare_url(make_path(repo_name, snapshot_name)) @@ -69,7 +78,8 @@ defmodule Elastix.Snapshot.Snapshot do {:ok, %HTTPoison.Response{...}} """ - @spec delete(String.t(), String.t(), String.t(), Keyword.t()) :: {:ok, %HTTPoison.Response{}} + @spec delete(String.t(), String.t(), String.t(), Keyword.t()) :: + {:ok, HTTPoison.Response.t()} def delete(elastic_url, repo_name, snapshot_name, options \\ []) do elastic_url |> prepare_url(make_path(repo_name, snapshot_name)) diff --git a/mix.exs b/mix.exs index e325cfc..40b8a9c 100644 --- a/mix.exs +++ b/mix.exs @@ -9,7 +9,7 @@ defmodule Elastix.Mixfile do app: :elastix, name: "Elastix", version: @version, - elixir: "~> 1.6", + elixir: "~> 1.18", build_embedded: Mix.env() == :prod, start_permanent: Mix.env() == :prod, aliases: aliases(), @@ -21,18 +21,18 @@ defmodule Elastix.Mixfile do def application do [ - applications: [:logger, :httpoison, :retry] + extra_applications: [:logger, :poison] ] end defp deps do [ {:ex_doc, ">= 0.0.0", only: :dev, runtime: false}, - {:credo, "~> 0.6", only: [:dev, :test]}, - {:mix_test_watch, "~> 0.3", only: [:test, :dev]}, - {:poison, "~> 3.0 or ~> 4.0", optional: true}, - {:httpoison, "~> 2.1.0"}, - {:retry, "~> 0.8"} + {:credo, "~> 1.7.13", only: [:dev, :test]}, + {:mix_test_watch, "~> 1.3.0", only: [:test, :dev]}, + {:poison, "~> 3.0 or ~> 6.0", optional: true}, + {:httpoison, "~> 2.2.3"}, + {:retry, "~> 0.19"} ] end diff --git a/mix.lock b/mix.lock index 634bb6c..13161b6 100644 --- a/mix.lock +++ b/mix.lock @@ -1,26 +1,24 @@ %{ - "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, - "certifi": {:hex, :certifi, "2.9.0", "6f2a475689dd47f19fb74334859d460a2dc4e3252a3324bd2111b8f0429e7e21", [:rebar3], [], "hexpm", "266da46bdb06d6c6d35fde799bcb28d36d985d424ad7c08b5bb48f5b5cdd4641"}, - "credo": {:hex, :credo, "0.9.0", "5d1b494e4f2dc672b8318e027bd833dda69be71eaac6eedd994678be74ef7cb4", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:poison, ">= 0.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm", "61de62970f70111434b84ec272cc969ac693af1f3e112f23f1ef055e57e838e1"}, - "earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], [], "hexpm", "1b34655872366414f69dd987cb121c049f76984b6ac69f52fff6d8fd64d29cfd"}, - "earmark_parser": {:hex, :earmark_parser, "1.4.12", "b245e875ec0a311a342320da0551da407d9d2b65d98f7a9597ae078615af3449", [:mix], [], "hexpm", "711e2cc4d64abb7d566d43f54b78f7dc129308a63bc103fbd88550d2174b3160"}, - "ex_doc": {:hex, :ex_doc, "0.24.2", "e4c26603830c1a2286dae45f4412a4d1980e1e89dc779fcd0181ed1d5a05c8d9", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "e134e1d9e821b8d9e4244687fb2ace58d479b67b282de5158333b0d57c6fb7da"}, - "fs": {:hex, :fs, "0.9.2", "ed17036c26c3f70ac49781ed9220a50c36775c6ca2cf8182d123b6566e49ec59", [:rebar], [], "hexpm", "9a00246e8af58cdf465ae7c48fd6fd7ba2e43300413dfcc25447ecd3bf76f0c1"}, - "hackney": {:hex, :hackney, "1.18.1", "f48bf88f521f2a229fc7bae88cf4f85adc9cd9bcf23b5dc8eb6a1788c662c4f6", [:rebar3], [{:certifi, "~> 2.9.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a4ecdaff44297e9b5894ae499e9a070ea1888c84afdd1fd9b7b2bc384950128e"}, - "httpoison": {:hex, :httpoison, "2.1.0", "655fd9a7b0b95ee3e9a3b535cf7ac8e08ef5229bab187fa86ac4208b122d934b", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "fc455cb4306b43827def4f57299b2d5ac8ac331cb23f517e734a4b78210a160c"}, - "ibrowse": {:git, "git://github.com/cmullaparthi/ibrowse.git", "d2e369ff42666c3574b8b7ec26f69027895c4d94", [tag: "v4.1.1"]}, + "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, + "certifi": {:hex, :certifi, "2.15.0", "0e6e882fcdaaa0a5a9f2b3db55b1394dba07e8d6d9bcad08318fb604c6839712", [:rebar3], [], "hexpm", "b147ed22ce71d72eafdad94f055165c1c182f61a2ff49df28bcc71d1d5b94a60"}, + "credo": {:hex, :credo, "1.7.13", "126a0697df6b7b71cd18c81bc92335297839a806b6f62b61d417500d1070ff4e", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "47641e6d2bbff1e241e87695b29f617f1a8f912adea34296fb10ecc3d7e9e84f"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"}, + "ex_doc": {:hex, :ex_doc, "0.39.1", "e19d356a1ba1e8f8cfc79ce1c3f83884b6abfcb79329d435d4bbb3e97ccc286e", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "8abf0ed3e3ca87c0847dfc4168ceab5bedfe881692f1b7c45f4a11b232806865"}, + "file_system": {:hex, :file_system, "1.1.1", "31864f4685b0148f25bd3fbef2b1228457c0c89024ad67f7a81a3ffbc0bbad3a", [:mix], [], "hexpm", "7a15ff97dfe526aeefb090a7a9d3d03aa907e100e262a0f8f7746b78f8f87a5d"}, + "hackney": {:hex, :hackney, "1.25.0", "390e9b83f31e5b325b9f43b76e1a785cbdb69b5b6cd4e079aa67835ded046867", [:rebar3], [{:certifi, "~> 2.15.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.4", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "7209bfd75fd1f42467211ff8f59ea74d6f2a9e81cbcee95a56711ee79fd6b1d4"}, + "httpoison": {:hex, :httpoison, "2.2.3", "a599d4b34004cc60678999445da53b5e653630651d4da3d14675fedc9dd34bd6", [:mix], [{:hackney, "~> 1.21", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "fa0f2e3646d3762fdc73edb532104c8619c7636a6997d20af4003da6cfc53e53"}, "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, - "makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"}, - "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, + "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, + "makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"}, + "makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"}, + "makeup_erlang": {:hex, :makeup_erlang, "1.0.2", "03e1804074b3aa64d5fad7aa64601ed0fb395337b982d9bcf04029d68d51b6a7", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "af33ff7ef368d5893e4a267933e7744e46ce3cf1f61e2dccf53a111ed3aa3727"}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, - "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, - "mix_test_watch": {:hex, :mix_test_watch, "0.5.0", "2c322d119a4795c3431380fca2bca5afa4dc07324bd3c0b9f6b2efbdd99f5ed3", [:mix], [{:fs, "~> 0.9.1", [hex: :fs, repo: "hexpm", optional: false]}], "hexpm", "90501b4ad90268127d1765c678a07872c921aebc672bd5fe218b00400bfb51b0"}, - "nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"}, - "parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"}, - "poison": {:hex, :poison, "4.0.1", "bcb755a16fac91cad79bfe9fc3585bb07b9331e50cfe3420a24bcc2d735709ae", [:mix], [], "hexpm", "ba8836feea4b394bb718a161fc59a288fe0109b5006d6bdf97b6badfcf6f0f25"}, - "retry": {:hex, :retry, "0.8.1", "46bd45c98dcba126bee04967d60f84ac13b854dfedaf6c2fb3b7f0cae884e090", [:mix], [], "hexpm", "a9f217e097a250f386b93bb7c2231b5668a70e04ed5ce8b9a90816b3a3acffba"}, - "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, - "ssl_verify_hostname": {:hex, :ssl_verify_hostname, "1.0.5", "2e73e068cd6393526f9fa6d399353d7c9477d6886ba005f323b592d389fb47be", [:make], []}, - "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"}, + "mimerl": {:hex, :mimerl, "1.4.0", "3882a5ca67fbbe7117ba8947f27643557adec38fa2307490c4c4207624cb213b", [:rebar3], [], "hexpm", "13af15f9f68c65884ecca3a3891d50a7b57d82152792f3e19d88650aa126b144"}, + "mix_test_watch": {:hex, :mix_test_watch, "1.3.0", "2ffc9f72b0d1f4ecf0ce97b044e0e3c607c3b4dc21d6228365e8bc7c2856dc77", [:mix], [{:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm", "f9e5edca976857ffac78632e635750d158df14ee2d6185a15013844af7570ffe"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"}, + "parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"}, + "poison": {:hex, :poison, "6.0.0", "9bbe86722355e36ffb62c51a552719534257ba53f3271dacd20fbbd6621a583a", [:mix], [{:decimal, "~> 2.1", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "bb9064632b94775a3964642d6a78281c07b7be1319e0016e1643790704e739a2"}, + "retry": {:hex, :retry, "0.19.0", "aeb326d87f62295d950f41e1255fe6f43280a1b390d36e280b7c9b00601ccbc2", [:mix], [], "hexpm", "85ef376aa60007e7bff565c366310966ec1bd38078765a0e7f20ec8a220d02ca"}, + "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"}, + "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.1", "a48703a25c170eedadca83b11e88985af08d35f37c6f664d6dcfb106a97782fc", [:rebar3], [], "hexpm", "b3a917854ce3ae233619744ad1e0102e05673136776fb2fa76234f3e03b23642"}, } diff --git a/test/elastix/bulk_test.exs b/test/elastix/bulk_test.exs index a7bd875..5acbca4 100644 --- a/test/elastix/bulk_test.exs +++ b/test/elastix/bulk_test.exs @@ -14,28 +14,33 @@ defmodule Elastix.BulkTest do end test "make_path should make url from index name, type, and query params" do - assert Bulk.make_path(@test_index, "tweet", version: 34, ttl: "1d") == - "/#{@test_index}/tweet/_bulk?version=34&ttl=1d" + assert Bulk.make_path(@test_index, version: 34, ttl: "1d") == + "/#{@test_index}/_bulk?version=34&ttl=1d" end test "make_path should make url from index name and query params" do - assert Bulk.make_path(@test_index, nil, version: 34, ttl: "1d") == + assert Bulk.make_path(@test_index, version: 34, ttl: "1d") == "/#{@test_index}/_bulk?version=34&ttl=1d" end test "make_path should make url from query params" do - assert Bulk.make_path(nil, nil, version: 34, ttl: "1d") == "/_bulk?version=34&ttl=1d" + assert Bulk.make_path(nil, version: 34, ttl: "1d") == "/_bulk?version=34&ttl=1d" end test "bulk accepts httpoison options" do lines = [ - %{index: %{_id: "1"}}, - %{field: "value1"}, - %{index: %{_id: "2"}}, - %{field: "value2"} - ] + %{index: %{_id: "1"}}, + %{field: "value1"}, + %{index: %{_id: "2"}}, + %{field: "value2"} + ] + {:error, %HTTPoison.Error{reason: :timeout}} = - Bulk.post @test_url, lines, index: @test_index, type: "message", httpoison_options: [recv_timeout: 0] + Bulk.post(@test_url, lines, + index: @test_index, + type: "message", + httpoison_options: [recv_timeout: 0] + ) end describe "test bulks with index and type in URL" do @@ -55,10 +60,10 @@ defmodule Elastix.BulkTest do assert response.status_code == 200 assert {:ok, %{status_code: 200}} = - Document.get(@test_url, @test_index, "message", "1") + Document.get(@test_url, @test_index, "_doc", "1") assert {:ok, %{status_code: 200}} = - Document.get(@test_url, @test_index, "message", "2") + Document.get(@test_url, @test_index, "_doc", "2") end test "post bulk with raw body should execute it", %{lines: lines} do @@ -73,23 +78,23 @@ defmodule Elastix.BulkTest do assert response.status_code == 200 assert {:ok, %{status_code: 200}} = - Document.get(@test_url, @test_index, "message", "1") + Document.get(@test_url, @test_index, "_doc", "1") assert {:ok, %{status_code: 200}} = - Document.get(@test_url, @test_index, "message", "2") + Document.get(@test_url, @test_index, "_doc", "2") end test "post bulk sending iolist should execute it", %{lines: lines} do {:ok, response} = - Bulk.post_to_iolist(@test_url, lines, index: @test_index, type: "message") + Bulk.post(@test_url, lines, index: @test_index, type: "message") assert response.status_code == 200 assert {:ok, %{status_code: 200}} = - Document.get(@test_url, @test_index, "message", "1") + Document.get(@test_url, @test_index, "_doc", "1") assert {:ok, %{status_code: 200}} = - Document.get(@test_url, @test_index, "message", "2") + Document.get(@test_url, @test_index, "_doc", "2") end end @@ -97,9 +102,9 @@ defmodule Elastix.BulkTest do setup do {:ok, lines: [ - %{index: %{_id: "1", _type: "message"}}, + %{index: %{_id: "1"}}, %{field: "value1"}, - %{index: %{_id: "2", _type: "message"}}, + %{index: %{_id: "2"}}, %{field: "value2"} ]} end @@ -110,10 +115,10 @@ defmodule Elastix.BulkTest do assert response.status_code == 200 assert {:ok, %{status_code: 200}} = - Document.get(@test_url, @test_index, "message", "1") + Document.get(@test_url, @test_index, "_doc", "1") assert {:ok, %{status_code: 200}} = - Document.get(@test_url, @test_index, "message", "2") + Document.get(@test_url, @test_index, "_doc", "2") end test "post bulk with raw body should execute it", %{lines: lines} do @@ -127,22 +132,22 @@ defmodule Elastix.BulkTest do assert response.status_code == 200 assert {:ok, %{status_code: 200}} = - Document.get(@test_url, @test_index, "message", "1") + Document.get(@test_url, @test_index, "_doc", "1") assert {:ok, %{status_code: 200}} = - Document.get(@test_url, @test_index, "message", "2") + Document.get(@test_url, @test_index, "_doc", "2") end test "post bulk sending iolist should execute it", %{lines: lines} do - {:ok, response} = Bulk.post_to_iolist(@test_url, lines, index: @test_index) + {:ok, response} = Bulk.post(@test_url, lines, index: @test_index) assert response.status_code == 200 assert {:ok, %{status_code: 200}} = - Document.get(@test_url, @test_index, "message", "1") + Document.get(@test_url, @test_index, "_doc", "1") assert {:ok, %{status_code: 200}} = - Document.get(@test_url, @test_index, "message", "2") + Document.get(@test_url, @test_index, "_doc", "2") end end @@ -150,9 +155,9 @@ defmodule Elastix.BulkTest do setup do {:ok, lines: [ - %{index: %{_id: "1", _type: "message", _index: @test_index}}, + %{index: %{_id: "1", _index: @test_index}}, %{field: "value1"}, - %{index: %{_id: "2", _type: "message", _index: @test_index}}, + %{index: %{_id: "2", _index: @test_index}}, %{field: "value2"} ]} end @@ -163,10 +168,10 @@ defmodule Elastix.BulkTest do assert response.status_code == 200 assert {:ok, %{status_code: 200}} = - Document.get(@test_url, @test_index, "message", "1") + Document.get(@test_url, @test_index, "_doc", "1") assert {:ok, %{status_code: 200}} = - Document.get(@test_url, @test_index, "message", "2") + Document.get(@test_url, @test_index, "_doc", "2") end test "post bulk with raw body should execute it", %{lines: lines} do @@ -179,22 +184,22 @@ defmodule Elastix.BulkTest do assert response.status_code == 200 assert {:ok, %{status_code: 200}} = - Document.get(@test_url, @test_index, "message", "1") + Document.get(@test_url, @test_index, "_doc", "1") assert {:ok, %{status_code: 200}} = - Document.get(@test_url, @test_index, "message", "2") + Document.get(@test_url, @test_index, "_doc", "2") end test "post bulk sending iolist should execute it", %{lines: lines} do - {:ok, response} = Bulk.post_to_iolist(@test_url, lines) + {:ok, response} = Bulk.post(@test_url, lines) assert response.status_code == 200 assert {:ok, %{status_code: 200}} = - Document.get(@test_url, @test_index, "message", "1") + Document.get(@test_url, @test_index, "_doc", "1") assert {:ok, %{status_code: 200}} = - Document.get(@test_url, @test_index, "message", "2") + Document.get(@test_url, @test_index, "_doc", "2") end end end diff --git a/test/elastix/document_test.exs b/test/elastix/document_test.exs index 3c5c614..1fe1461 100644 --- a/test/elastix/document_test.exs +++ b/test/elastix/document_test.exs @@ -20,47 +20,45 @@ defmodule Elastix.DocumentTest do test "make_path should make url from index name, type, query params, id, and suffix" do assert Document.make_path( @test_index, - "tweet", + "_doc", [version: 34, ttl: "1d"], 2, "_update" - ) == "/#{@test_index}/tweet/2/_update?version=34&ttl=1d" + ) == "/#{@test_index}/_doc/2/_update?version=34&ttl=1d" end test "make_path without and id should make url from index name, type, and query params" do - assert Document.make_path(@test_index, "tweet", version: 34, ttl: "1d") == - "/#{@test_index}/tweet?version=34&ttl=1d" + assert Document.make_path(@test_index, "_doc", version: 34, ttl: "1d") == + "/#{@test_index}/_doc?version=34&ttl=1d" end test "index should create and index with data" do - {:ok, response} = Document.index(@test_url, @test_index, "message", 1, @data) + {:ok, response} = Document.index(@test_url, @test_index, "_doc", 1, @data) assert response.status_code == 201 assert response.body["_id"] == "1" assert response.body["_index"] == @test_index - assert response.body["_type"] == "message" - assert response.body["created"] == true + assert response.body["result"] == "created" end test "index_new should index data without an id" do - {:ok, response} = Document.index_new(@test_url, @test_index, "message", @data) + {:ok, response} = Document.index_new(@test_url, @test_index, "_doc", @data) assert response.status_code == 201 assert response.body["_id"] assert response.body["_index"] == @test_index - assert response.body["_type"] == "message" - assert response.body["created"] == true + assert response.body["result"] == "created" end test "get should return 404 if not index was created" do - {:ok, response} = Document.get(@test_url, @test_index, "message", 1) + {:ok, response} = Document.get(@test_url, @test_index, "_doc", 1) assert response.status_code == 404 end test "get should return data with 200 after index" do - Document.index(@test_url, @test_index, "message", 1, @data) - {:ok, response} = Document.get(@test_url, @test_index, "message", 1) + Document.index(@test_url, @test_index, "_doc", 1, @data) + {:ok, response} = Document.get(@test_url, @test_index, "_doc", 1) body = response.body assert response.status_code == 200 @@ -70,30 +68,30 @@ defmodule Elastix.DocumentTest do end test "delete should delete created index" do - Document.index(@test_url, @test_index, "message", 1, @data) + Document.index(@test_url, @test_index, "_doc", 1, @data) - {:ok, response} = Document.get(@test_url, @test_index, "message", 1) + {:ok, response} = Document.get(@test_url, @test_index, "_doc", 1) assert response.status_code == 200 - {:ok, response} = Document.delete(@test_url, @test_index, "message", 1) + {:ok, response} = Document.delete(@test_url, @test_index, "_doc", 1) assert response.status_code == 200 - {:ok, response} = Document.get(@test_url, @test_index, "message", 1) + {:ok, response} = Document.get(@test_url, @test_index, "_doc", 1) assert response.status_code == 404 end test "delete by query should remove all docs that match" do - Document.index(@test_url, @test_index, "message", 1, @data, refresh: true) - Document.index(@test_url, @test_index, "message", 2, @data, refresh: true) + Document.index(@test_url, @test_index, "_doc", 1, @data, refresh: true) + Document.index(@test_url, @test_index, "_doc", 2, @data, refresh: true) no_match = Map.put(@data, :user, "no match") - Document.index(@test_url, @test_index, "message", 3, no_match, refresh: true) + Document.index(@test_url, @test_index, "_doc", 3, no_match, refresh: true) match_all_query = %{"query" => %{"match_all" => %{}}} - {:ok, response} = Search.search(@test_url, @test_index, ["message"], match_all_query) + {:ok, response} = Search.search(@test_url, @test_index, [], match_all_query) assert response.status_code == 200 - assert response.body["hits"]["total"] == 3 + assert response.body["hits"]["total"]["value"] == 3 query = %{"query" => %{"match" => %{"user" => "örelbörel"}}} @@ -102,22 +100,22 @@ defmodule Elastix.DocumentTest do assert response.status_code == 200 - {:ok, response} = Search.search(@test_url, @test_index, ["message"], match_all_query) + {:ok, response} = Search.search(@test_url, @test_index, [], match_all_query) assert response.status_code == 200 - assert response.body["hits"]["total"] == 1 + assert response.body["hits"]["total"]["value"] == 1 end test "update can partially update document" do - Document.index(@test_url, @test_index, "message", 1, @data) + Document.index(@test_url, @test_index, "_doc", 1, @data, refresh: true) new_post_date = "2017-03-17T14:12:12" patch = %{doc: %{post_date: new_post_date}} - {:ok, response} = Document.update(@test_url, @test_index, "message", 1, patch) + {:ok, response} = Document.update(@test_url, @test_index, 1, patch) assert response.status_code == 200 {:ok, %{body: body, status_code: status_code}} = - Document.get(@test_url, @test_index, "message", 1) + Document.get(@test_url, @test_index, "_doc", 1) assert status_code == 200 assert body["_source"]["user"] == "örelbörel" @@ -126,8 +124,8 @@ defmodule Elastix.DocumentTest do end test "update by query can update a list of docs by matching query" do - Document.index(@test_url, @test_index, "message", 1, @data, refresh: true) - Document.index(@test_url, @test_index, "message", 2, @data, refresh: true) + Document.index(@test_url, @test_index, "_doc", 1, @data, refresh: true) + Document.index(@test_url, @test_index, "_doc", 2, @data, refresh: true) new_post_date = "2020-06-03T14:12:12" @@ -144,7 +142,7 @@ defmodule Elastix.DocumentTest do assert response.status_code == 200 {:ok, %{body: body, status_code: status_code}} = - Document.get(@test_url, @test_index, "message", 1) + Document.get(@test_url, @test_index, "_doc", 1) assert status_code == 200 assert body["_source"]["user"] == "örelbörel" @@ -152,7 +150,7 @@ defmodule Elastix.DocumentTest do assert body["_source"]["message"] == "trying out Elasticsearch" {:ok, %{body: body, status_code: status_code}} = - Document.get(@test_url, @test_index, "message", 2) + Document.get(@test_url, @test_index, "_doc", 2) assert status_code == 200 assert body["_source"]["user"] == "örelbörel" @@ -161,7 +159,7 @@ defmodule Elastix.DocumentTest do end test "update by query doesnt update when no matches are found" do - Document.index(@test_url, @test_index, "message", 1, @data, refresh: true) + Document.index(@test_url, @test_index, "_doc", 1, @data, refresh: true) script = %{ inline: "ctx._source.message = 'updated message'", @@ -176,7 +174,7 @@ defmodule Elastix.DocumentTest do assert response.status_code == 200 {:ok, %{body: body, status_code: status_code}} = - Document.get(@test_url, @test_index, "message", 1) + Document.get(@test_url, @test_index, "_doc", 1) assert status_code == 200 assert body["_source"]["user"] == "örelbörel" @@ -185,19 +183,17 @@ defmodule Elastix.DocumentTest do end test "can get multiple documents (multi get)" do - Document.index(@test_url, @test_index, "message", 1, @data) - Document.index(@test_url, @test_index, "message", 2, @data) + Document.index(@test_url, @test_index, "_doc", 1, @data) + Document.index(@test_url, @test_index, "_doc", 2, @data) query = %{ "docs" => [ %{ "_index" => @test_index, - "_type" => "message", "_id" => "1" }, %{ "_index" => @test_index, - "_type" => "message", "_id" => "2" } ] @@ -210,17 +206,15 @@ defmodule Elastix.DocumentTest do end test "can get multiple documents (multi get with index)" do - Document.index(@test_url, @test_index, "message", 1, @data) - Document.index(@test_url, @test_index, "message", 2, @data) + Document.index(@test_url, @test_index, "_doc", 1, @data) + Document.index(@test_url, @test_index, "_doc", 2, @data) query = %{ "docs" => [ %{ - "_type" => "message", "_id" => "1" }, %{ - "_type" => "message", "_id" => "2" } ] @@ -234,8 +228,8 @@ defmodule Elastix.DocumentTest do end test "can get multiple documents (multi get with index and type)" do - Document.index(@test_url, @test_index, "message", 1, @data) - Document.index(@test_url, @test_index, "message", 2, @data) + Document.index(@test_url, @test_index, "_doc", 1, @data) + Document.index(@test_url, @test_index, "_doc", 2, @data) query = %{ "docs" => [ @@ -249,7 +243,7 @@ defmodule Elastix.DocumentTest do } {:ok, %{body: body, status_code: status_code}} = - Document.mget(@test_url, query, @test_index, "message") + Document.mget(@test_url, query, @test_index) assert status_code === 200 assert length(body["docs"]) == 2 diff --git a/test/elastix/http_test.exs b/test/elastix/http_test.exs index 57b95a2..f2defc5 100644 --- a/test/elastix/http_test.exs +++ b/test/elastix/http_test.exs @@ -19,14 +19,14 @@ defmodule Elastix.HTTPTest do assert response.status_code == 200 end - test "post should respond with 400" do + test "post should respond with 405" do {_, response} = HTTP.post(@test_url, []) - assert response.status_code == 400 + assert response.status_code == 405 end - test "put should respond with 400" do + test "put should respond with 405" do {_, response} = HTTP.put(@test_url, []) - assert response.status_code == 400 + assert response.status_code == 405 end test "delete should respond with 400" do @@ -46,9 +46,9 @@ defmodule Elastix.HTTPTest do test "process_response_body parsed the body into an atom key map if configured" do body = "{\"some\":\"json\"}" - Application.put_env(:elastix, :poison_options, keys: :atoms) + Application.put_env(:elastix, :json_options, keys: :atoms) assert HTTP.process_response_body(body) == %{some: "json"} - Application.delete_env(:elastix, :poison_options) + Application.delete_env(:elastix, :json_options) end test "adding custom headers" do diff --git a/test/elastix/mapping_test.exs b/test/elastix/mapping_test.exs index 0699a3d..5031636 100644 --- a/test/elastix/mapping_test.exs +++ b/test/elastix/mapping_test.exs @@ -4,6 +4,10 @@ defmodule Elastix.MappingTest do alias Elastix.Mapping alias Elastix.Document + @moduledoc """ + Tests for the Elastix.Mapping module. + """ + @test_url Elastix.config(:test_url) @test_index Elastix.config(:test_index) @test_index2 Elastix.config(:test_index) <> "_2" @@ -31,22 +35,14 @@ defmodule Elastix.MappingTest do :ok end - defp elasticsearch_version do - %HTTPoison.Response{body: %{"version" => %{"number" => v}}, status_code: 200} = - Elastix.HTTP.get!(@test_url) - - v |> String.split([".", "-"]) |> Enum.take(3) |> Enum.map(&String.to_integer/1) - |> List.to_tuple() - end - test "make_path should make url from index names, types, and query params" do assert Mapping.make_path([@test_index], ["tweet"], version: 34, ttl: "1d") == - "/#{@test_index}/_mapping/tweet?version=34&ttl=1d" + "/#{@test_index}/_mapping?version=34&ttl=1d" end test "make_all_path should make url from types, and query params" do assert Mapping.make_all_path(["tweet"], version: 34, ttl: "1d") == - "/_mapping/tweet?version=34&ttl=1d" + "/_mapping?version=34&ttl=1d" end test "make_all_path should make url from query params" do @@ -77,13 +73,8 @@ defmodule Elastix.MappingTest do Index.create(@test_url, @test_index, %{}) {:ok, response} = Mapping.get(@test_url, @test_index, "message") - if elasticsearch_version() >= {5, 5, 0} do - assert response.body["error"]["reason"] == "type[[message]] missing" - else - assert response.body == %{} - end - - assert response.status_code == 404 + assert response.status_code == 200 + assert response.body[@test_index]["mappings"] == %{} end test "get mapping should return mapping" do @@ -92,7 +83,7 @@ defmodule Elastix.MappingTest do {:ok, response} = Mapping.get(@test_url, @test_index, "message") assert response.status_code == 200 - assert response.body[@test_index]["mappings"]["message"] == @target_mapping + assert response.body[@test_index]["mappings"] == @target_mapping end test "get mapping for several types should return several mappings" do @@ -102,8 +93,7 @@ defmodule Elastix.MappingTest do {:ok, response} = Mapping.get(@test_url, @test_index, ["message", "comment"]) assert response.status_code == 200 - assert response.body[@test_index]["mappings"]["message"] == @target_mapping - assert response.body[@test_index]["mappings"]["comment"] == @target_mapping + assert response.body[@test_index]["mappings"] == @target_mapping end test "get_all mappings should return mappings for all indexes and types" do @@ -114,8 +104,8 @@ defmodule Elastix.MappingTest do {:ok, response} = Mapping.get_all(@test_url) assert response.status_code == 200 - assert response.body[@test_index]["mappings"]["message"] == @target_mapping - assert response.body[@test_index2]["mappings"]["comment"] == @target_mapping + assert response.body[@test_index]["mappings"] == @target_mapping + assert response.body[@test_index2]["mappings"] == @target_mapping end test "get_all_with_type mappings should return mapping for specifieds types in all indexes" do @@ -126,20 +116,18 @@ defmodule Elastix.MappingTest do {:ok, response} = Mapping.get_all_with_type(@test_url, ["message", "comment"]) assert response.status_code == 200 - assert response.body[@test_index]["mappings"]["message"] == @target_mapping - assert response.body[@test_index2]["mappings"]["comment"] == @target_mapping + assert response.body[@test_index]["mappings"] == @target_mapping + assert response.body[@test_index2]["mappings"] == @target_mapping end test "put document with mapping should put document" do - Index.create(@test_url, @test_index, %{}) - Mapping.put(@test_url, @test_index, "message", @mapping) + Index.create(@test_url, @test_index, %{mappings: @mapping}) - {:ok, response} = Document.index(@test_url, @test_index, "message", 1, @data) + {:ok, response} = Document.index(@test_url, @test_index, "_doc", 1, @data) assert response.status_code == 201 assert response.body["_id"] == "1" assert response.body["_index"] == @test_index - assert response.body["_type"] == "message" - assert response.body["created"] == true + assert response.body["result"] == "created" end end diff --git a/test/elastix/search_test.exs b/test/elastix/search_test.exs index 84bb2e4..0319c35 100644 --- a/test/elastix/search_test.exs +++ b/test/elastix/search_test.exs @@ -33,7 +33,7 @@ defmodule Elastix.SearchTest do test "make_path should make path from id and url" do path = Search.make_path(@test_index, ["tweet", "product"], ttl: "1d", timeout: 123) - assert path == "/#{@test_index}/tweet,product/_search?ttl=1d&timeout=123" + assert path == "/#{@test_index}/_search?ttl=1d&timeout=123" end test "make_path should make path that can interchange api type" do @@ -45,11 +45,11 @@ defmodule Elastix.SearchTest do "_count" ) - assert path == "/#{@test_index}/tweet,product/_count?ttl=1d&timeout=123" + assert path == "/#{@test_index}/_count?ttl=1d&timeout=123" end test "search should return with status 200" do - Document.index(@test_url, @test_index, "message", 1, @document_data, refresh: true) + Document.index(@test_url, @test_index, "_doc", 1, @document_data, refresh: true) {:ok, response} = Search.search(@test_url, @test_index, [], @query_data) @@ -57,15 +57,15 @@ defmodule Elastix.SearchTest do end test "search accepts httpoison options" do - Document.index(@test_url, @test_index, "message", 1, @document_data, refresh: true) + Document.index(@test_url, @test_index, "_doc", 1, @document_data, refresh: true) {:error, %HTTPoison.Error{reason: :timeout}} = Search.search(@test_url, @test_index, [], @query_data, [], recv_timeout: 0) end test "search accepts a list of indexes" do - Document.index(@test_url, @test_index, "message", 1, @document_data, refresh: true) - Document.index(@test_url, @test_index_2, "message", 1, @document_data, refresh: true) + Document.index(@test_url, @test_index, "_doc", 1, @document_data, refresh: true) + Document.index(@test_url, @test_index_2, "_doc", 1, @document_data, refresh: true) {:ok, %Response{body: body} = response} = Search.search(@test_url, [@test_index, @test_index_2], [], @query_data) @@ -75,8 +75,8 @@ defmodule Elastix.SearchTest do end test "search accepts a list of requests" do - Document.index(@test_url, @test_index, "message", 1, @document_data, refresh: true) - Document.index(@test_url, @test_index, "message", 2, @document_data, refresh: true) + Document.index(@test_url, @test_index, "_doc", 1, @document_data, refresh: true) + Document.index(@test_url, @test_index, "_doc", 2, @document_data, refresh: true) {:ok, response} = Search.search(@test_url, @test_index, [], [%{}, @query_data, %{}, @query_data]) @@ -91,7 +91,7 @@ defmodule Elastix.SearchTest do Document.index( @test_url, @test_index, - "message", + "_doc", i, @document_data, refresh: true @@ -114,7 +114,7 @@ defmodule Elastix.SearchTest do end test "count should return with status 200" do - Document.index(@test_url, @test_index, "message", 1, @document_data, refresh: true) + Document.index(@test_url, @test_index, "_doc", 1, @document_data, refresh: true) {:ok, response} = Search.count(@test_url, @test_index, [], @query_data) diff --git a/test/elastix/snapshot/snapshot_test.exs b/test/elastix/snapshot/snapshot_test.exs index 8dd8709..cc2eefc 100644 --- a/test/elastix/snapshot/snapshot_test.exs +++ b/test/elastix/snapshot/snapshot_test.exs @@ -12,6 +12,7 @@ defmodule Elastix.Snapshot.SnapshotTest do use ExUnit.Case use Retry + import Retry.DelayStreams alias Elastix.Index alias Elastix.Snapshot.{Repository, Snapshot} @@ -81,26 +82,20 @@ defmodule Elastix.Snapshot.SnapshotTest do wait_for_completion: true ) - wait lin_backoff(500, 1) |> expiry(5_000) do - ( - {:ok, %{body: %{"snapshots" => snapshots}}} = - Snapshot.status(@test_url, @test_repository, "elastix_test_snapshot_2") + wait linear_backoff(500, 1) |> expiry(5_000) do + {:ok, %{body: %{"snapshots" => snapshots}}} = + Snapshot.status(@test_url, @test_repository, "elastix_test_snapshot_2") - snapshot = List.first(snapshots) - snapshot["state"] == "SUCCESS" - ) - - then + snapshot = List.first(snapshots) + snapshot["state"] == "SUCCESS" + end - ( - {:ok, %{body: %{"snapshots" => snapshots}}} = - Snapshot.get(@test_url, @test_repository, "elastix_test_snapshot_2") + {:ok, %{body: %{"snapshots" => snapshots}}} = + Snapshot.get(@test_url, @test_repository, "elastix_test_snapshot_2") - snapshot = List.first(snapshots) - assert Enum.member?(snapshot["indices"], "elastix_test_index_1") - assert Enum.member?(snapshot["indices"], "elastix_test_index_2") - ) - end + snapshot = List.first(snapshots) + assert Enum.member?(snapshot["indices"], "elastix_test_index_1") + assert Enum.member?(snapshot["indices"], "elastix_test_index_2") end test "a snapshot of a single index in the cluster" do @@ -112,26 +107,20 @@ defmodule Elastix.Snapshot.SnapshotTest do wait_for_completion: true ) - wait lin_backoff(500, 1) |> expiry(5_000) do - ( - {:ok, %{body: %{"snapshots" => snapshots}}} = - Snapshot.status(@test_url, @test_repository, "elastix_test_snapshot_1") + wait linear_backoff(500, 1) |> expiry(5_000) do + {:ok, %{body: %{"snapshots" => snapshots}}} = + Snapshot.status(@test_url, @test_repository, "elastix_test_snapshot_1") - snapshot = List.first(snapshots) - snapshot["state"] == "SUCCESS" - ) - - then + snapshot = List.first(snapshots) + snapshot["state"] == "SUCCESS" + end - ( - {:ok, %{body: %{"snapshots" => snapshots}}} = - Snapshot.get(@test_url, @test_repository, "elastix_test_snapshot_1") + {:ok, %{body: %{"snapshots" => snapshots}}} = + Snapshot.get(@test_url, @test_repository, "elastix_test_snapshot_1") - snapshot = List.first(snapshots) - assert Enum.member?(snapshot["indices"], "elastix_test_index_1") - refute Enum.member?(snapshot["indices"], "elastix_test_index_2") - ) - end + snapshot = List.first(snapshots) + assert Enum.member?(snapshot["indices"], "elastix_test_index_1") + refute Enum.member?(snapshot["indices"], "elastix_test_index_2") end end @@ -145,39 +134,29 @@ defmodule Elastix.Snapshot.SnapshotTest do wait_for_completion: true ) - wait lin_backoff(500, 1) |> expiry(5_000) do - ( - {:ok, %{body: %{"snapshots" => snapshots}}} = - Snapshot.status(@test_url, @test_repository, "elastix_test_snapshot_4") + wait linear_backoff(500, 1) |> expiry(5_000) do + {:ok, %{body: %{"snapshots" => snapshots}}} = + Snapshot.status(@test_url, @test_repository, "elastix_test_snapshot_4") - snapshot = List.first(snapshots) - snapshot["state"] == "SUCCESS" - ) - - then - - ( - Index.close(@test_url, "elastix_test_index_1") - Index.close(@test_url, "elastix_test_index_2") - Index.delete(@test_url, "elastix_test_index_1") - Index.delete(@test_url, "elastix_test_index_2") - ) + snapshot = List.first(snapshots) + snapshot["state"] == "SUCCESS" end - wait lin_backoff(500, 1) |> expiry(5_000) do - ( - {:ok, %{status_code: 404}} = Index.get(@test_url, "elastix_test_index_1") - {:ok, %{status_code: 404}} = Index.get(@test_url, "elastix_test_index_2") - ) - - then + Index.close(@test_url, "elastix_test_index_1") + Index.close(@test_url, "elastix_test_index_2") + Index.delete(@test_url, "elastix_test_index_1") + Index.delete(@test_url, "elastix_test_index_2") - Snapshot.restore(@test_url, @test_repository, "elastix_test_snapshot_4", %{ - partial: true - }) + wait linear_backoff(500, 1) |> expiry(5_000) do + {:ok, %{status_code: 404}} = Index.get(@test_url, "elastix_test_index_1") + {:ok, %{status_code: 404}} = Index.get(@test_url, "elastix_test_index_2") end - wait lin_backoff(500, 1) |> expiry(5_000) do + Snapshot.restore(@test_url, @test_repository, "elastix_test_snapshot_4", %{ + partial: true + }) + + wait linear_backoff(500, 1) |> expiry(5_000) do {:ok, %{status_code: 200}} = Index.get(@test_url, "elastix_test_index_1") {:ok, %{status_code: 200}} = Index.get(@test_url, "elastix_test_index_2") end @@ -192,39 +171,29 @@ defmodule Elastix.Snapshot.SnapshotTest do wait_for_completion: true ) - wait lin_backoff(500, 1) |> expiry(5_000) do - ( - {:ok, %{status_code: 200, body: %{"snapshots" => snapshots}}} = - Snapshot.status(@test_url, @test_repository, "elastix_test_snapshot_3") - - snapshot = List.first(snapshots) - snapshot["state"] == "SUCCESS" - ) + wait linear_backoff(500, 1) |> expiry(5_000) do + {:ok, %{status_code: 200, body: %{"snapshots" => snapshots}}} = + Snapshot.status(@test_url, @test_repository, "elastix_test_snapshot_3") - then - - ( - Index.close(@test_url, "elastix_test_index_3") - Index.close(@test_url, "elastix_test_index_4") - Index.delete(@test_url, "elastix_test_index_3") - Index.delete(@test_url, "elastix_test_index_4") - ) + snapshot = List.first(snapshots) + snapshot["state"] == "SUCCESS" end - wait lin_backoff(500, 1) |> expiry(5_000) do - ( - {:ok, %{status_code: 404}} = Index.get(@test_url, "elastix_test_index_3") - {:ok, %{status_code: 404}} = Index.get(@test_url, "elastix_test_index_4") - ) - - then + Index.close(@test_url, "elastix_test_index_3") + Index.close(@test_url, "elastix_test_index_4") + Index.delete(@test_url, "elastix_test_index_3") + Index.delete(@test_url, "elastix_test_index_4") - Snapshot.restore(@test_url, @test_repository, "elastix_test_snapshot_3", %{ - indices: "elastix_test_index_3" - }) + wait linear_backoff(500, 1) |> expiry(5_000) do + {:ok, %{status_code: 404}} = Index.get(@test_url, "elastix_test_index_3") + {:ok, %{status_code: 404}} = Index.get(@test_url, "elastix_test_index_4") end - wait lin_backoff(500, 1) |> expiry(5_000) do + Snapshot.restore(@test_url, @test_repository, "elastix_test_snapshot_3", %{ + indices: "elastix_test_index_3" + }) + + wait linear_backoff(500, 1) |> expiry(5_000) do {:ok, %{status_code: 200}} = Index.get(@test_url, "elastix_test_index_3") {:ok, %{status_code: 404}} = Index.get(@test_url, "elastix_test_index_4") end @@ -250,7 +219,7 @@ defmodule Elastix.Snapshot.SnapshotTest do indices: "elastix_test_index_5" }) - wait lin_backoff(500, 1) |> expiry(5_000) do + wait linear_backoff(500, 1) |> expiry(5_000) do {:ok, %{status_code: 200}} = Snapshot.status(@test_url, @test_repository, "elastix_test_snapshot_5") end