diff --git a/.travis.yml b/.travis.yml index 04320fd..5c32b7f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,29 +2,14 @@ sudo: required language: elixir elixir: - - 1.3.0 - - 1.4.1 - - 1.5.2 + - 1.7.4 matrix: include: - - elixir '1.3.0' - - otp_release '18.0' - include: - - elixir '1.4.1' - - otp_release '19.3' - include: - - elixir '1.5.2' + - elixir '1.7.4' - otp_release '20.0' before_install: - - curl -O https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.1.1/elasticsearch-2.1.1.deb && sudo dpkg -i --force-confnew elasticsearch-2.1.1.deb + - curl -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.2.deb && sudo dpkg -i --force-confnew elasticsearch-6.6.2.deb - sudo service elasticsearch start # - wget -nv --tries 4 --retry-connrefused --no-check-certificate 127.0.0.1:9200 - -notifications: - email: false - slack: - rooms: - - zatvobor:eLjCTZD2l85xl19hsSdxkMdN##oss-feed - on_success: change diff --git a/README.md b/README.md index cd5c8ad..f0edb0c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![Build Status](https://travis-ci.org/Zatvobor/tirexs.svg?branch=master)](https://travis-ci.org/Zatvobor/tirexs) [![HEX version](https://img.shields.io/hexpm/v/tirexs.svg)](https://hex.pm/packages/tirexs) [![HEX downloads](https://img.shields.io/hexpm/dw/tirexs.svg)](https://hex.pm/packages/tirexs) [![Deps Status](https://beta.hexfaktor.org/badge/all/github/Zatvobor/tirexs.svg)](https://beta.hexfaktor.org/github/Zatvobor/tirexs) -An Elixir flavored HTTP client and DSL library for building JSON based settings, mappings, queries and percolators to Elasticsearch engine. +An Elixir flavored HTTP client and DSL library for building JSON based settings, mappings, queries to Elasticsearch engine. ## Getting Started diff --git a/examples/percolator.exs b/examples/percolator.exs deleted file mode 100644 index e78cff0..0000000 --- a/examples/percolator.exs +++ /dev/null @@ -1,26 +0,0 @@ -# -# Run this example from console manually: -# -# $ mix run -r examples/percolator.exs -# # => curl -X PUT -d '{"query": {"term": {"field1": "value1"}}}' http://127.0.0.1:9200/bear_test/.percolator/1 -# -# Run this example from Elixir environment (`iex -S mix`): -# -# iex> Path.expand("examples/percolator.exs") |> Tirexs.load_file -# -Tirexs.DSL.define(fn() -> - import Tirexs.Percolator - - query = percolator [index: "bear_test", name: "1"] do - query do - term "field1", "value1" - end - end - - # Below a couple of code lines which could be useful for debugging and getting actual JSON string - - # url = Tirexs.HTTP.url("test/.percolator/1") - # json = JSX.prettify!(JSX.encode!(Tirexs.Percolator.to_resource_json(query))) - # IO.puts "\n# => curl -X PUT -d '#{json}' #{url}" - -[percolator: query] end) diff --git a/examples/settings.exs b/examples/settings.exs index 22875b1..a56084e 100644 --- a/examples/settings.exs +++ b/examples/settings.exs @@ -18,11 +18,6 @@ Tirexs.DSL.define([index: "bear_test"], fn(index) -> filter "substring", [type: "nGram", min_gram: 2, max_gram: 32] tokenizer "dot-tokenizer", [type: "path_hierarchy", delimiter: "."] end - - cache max_size: -1 - translog disable_flush: false - set number_of_replicas: 3 - blocks write: true end # Below a couple of code lines which could be useful for debugging and getting actual JSON string diff --git a/lib/tirexs/dsl.ex b/lib/tirexs/dsl.ex index 5ce1af3..0c1e0de 100644 --- a/lib/tirexs/dsl.ex +++ b/lib/tirexs/dsl.ex @@ -2,8 +2,7 @@ defmodule Tirexs.DSL do @moduledoc """ This module represents a main entry point for creating resources from DSL. - The resource types are allowed to be `settings`, `mapping`, `search`, or - `percolator` definitions. + The resource types are allowed to be `settings`, `mapping`, `search`, definitions. This convenience allows you to define particular resources over `*.exs` snippets and load them by request, for instance: @@ -17,7 +16,7 @@ defmodule Tirexs.DSL do @doc """ Calls a `definition_fn/1,2` function and will create their resource. The resource - types are allowed to be `settings`, `mapping`, `search`, or `percolator`. + types are allowed to be `settings`, `mapping`, `search`. """ def define(initial, definition_fn) do @@ -33,7 +32,7 @@ defmodule Tirexs.DSL do @doc """ Calls a `definition_fn/0,1` function and will create their resource. The resource - types are allowed to be `settings`, `mapping`, `search`, or `percolator`. + types are allowed to be `settings`, `mapping`, `search`. """ def define(definition_fn) when is_function(definition_fn) do @@ -48,14 +47,13 @@ defmodule Tirexs.DSL do end - alias Tirexs.{ElasticSearch.Settings, Mapping, Query, Percolator} + alias Tirexs.{ElasticSearch.Settings, Mapping, Query} defp create_resource(definition, uri \\ Tirexs.get_uri_env()) do cond do definition[:settings] -> Settings.create_resource(definition, uri) definition[:mapping] -> Mapping.create_resource(definition, uri) definition[:search] -> Query.create_resource(definition, uri) - definition[:percolator] -> Percolator.create_resource(definition[:percolator], uri) end end end diff --git a/lib/tirexs/http.ex b/lib/tirexs/http.ex index a85b4df..cf2f476 100644 --- a/lib/tirexs/http.ex +++ b/lib/tirexs/http.ex @@ -322,13 +322,13 @@ defmodule Tirexs.HTTP do @doc false def do_request(method, url, body \\ []) do - { url, content_type, options } = { String.to_char_list(url), 'application/json', [{:body_format, :binary}] } + { url, content_type, options } = { String.to_charlist(url), 'application/json', [{:body_format, :binary}] } case method do :get -> ( request(method, {url, []}, [], []) |> response() ) :head -> ( request(method, {url, []}, [], []) |> response() ) :delete -> ( request(method, {url, [], content_type, []}, [], []) |> response() ) - :put -> ( request(method, {url, headers, content_type, body}, [], options) |> response() ) - :post -> ( request(method, {url, headers, content_type, body}, [], options) |> response() ) + :put -> ( request(method, {url, headers(), content_type, body}, [], options) |> response() ) + :post -> ( request(method, {url, headers(), content_type, body}, [], options) |> response() ) end end diff --git a/lib/tirexs/index/logic.ex b/lib/tirexs/index/logic.ex index 831b8bf..9c436b2 100644 --- a/lib/tirexs/index/logic.ex +++ b/lib/tirexs/index/logic.ex @@ -10,6 +10,14 @@ defmodule Tirexs.Index.Logic do end) end + @doc false + def put_index_setting(index, type) do + update_in(index[:settings][type], fn + nil -> [] + settings -> settings + end) + end + @doc false def put_index_setting(index, main_type, type) do update_in(index[:settings][main_type][type], fn @@ -18,6 +26,14 @@ defmodule Tirexs.Index.Logic do end) end + @doc false + def put_index_setting_nested_type(index, type, nested_type) do + update_in(index[:settings][type][nested_type], fn + nil -> [] + settings -> settings + end) + end + @doc false def put_index_setting_nested_type(index, main_type, type, nested_type) do update_in(index[:settings][main_type][type][nested_type], fn @@ -28,7 +44,12 @@ defmodule Tirexs.Index.Logic do @doc false def add_index_setting(index, value) do - update_in(index[:settings][:index], &(&1 ++ value)) + update_in(index[:settings], &(&1 ++ value)) + end + + @doc false + def add_index_setting(index, type, value) do + update_in(index[:settings][type], &(&1 ++ value)) end @doc false @@ -36,6 +57,11 @@ defmodule Tirexs.Index.Logic do update_in(index[:settings][main_type][type], &(&1 ++ value)) end + @doc false + def add_index_setting_nested_type(index, type, nested_type, value) do + update_in(index[:settings][type][nested_type], &(&1 ++ value)) + end + @doc false def add_index_setting_nested_type(index, main_type, type, nested_type, value) do update_in(index[:settings][main_type][type][nested_type], &(&1 ++ value)) diff --git a/lib/tirexs/index/settings.ex b/lib/tirexs/index/settings.ex index 9f288dd..c59421a 100644 --- a/lib/tirexs/index/settings.ex +++ b/lib/tirexs/index/settings.ex @@ -9,7 +9,6 @@ defmodule Tirexs.Index.Settings do defmacro settings([do: block]) do quote do var!(index) = Keyword.put(var!(index), :settings, []) - var!(index) = put_setting(var!(index), :index) unquote(block) end end @@ -50,19 +49,19 @@ defmodule Tirexs.Index.Settings do @doc false defmacro blocks(value) do quote do - var!(index) = put_index_setting(var!(index), :index, :blocks) + var!(index) = put_index_setting(var!(index), :blocks) value = unquote(value) - var!(index) = add_index_setting(var!(index), :index, :blocks, value) + var!(index) = add_index_setting(var!(index), :blocks, value) end end @doc false defmacro cache(value) do quote do - var!(index) = put_index_setting(var!(index), :index, :cache) - var!(index) = put_index_setting_nested_type(var!(index), :index, :cache, :filter) + var!(index) = put_index_setting(var!(index), :cache) + var!(index) = put_index_setting_nested_type(var!(index), :cache, :filter) value = unquote(value) - var!(index) = add_index_setting_nested_type(var!(index), :index, :cache, :filter, value) + var!(index) = add_index_setting_nested_type(var!(index), :cache, :filter, value) end end @@ -96,9 +95,9 @@ defmodule Tirexs.Index.Settings do @doc false defmacro translog(value) do quote do - var!(index) = put_index_setting(var!(index), :index, :translog) + var!(index) = put_index_setting(var!(index), :translog) value = unquote(value) - var!(index) = add_index_setting(var!(index), :index, :translog, value) + var!(index) = add_index_setting(var!(index), :translog, value) end end end diff --git a/lib/tirexs/percolator.ex b/lib/tirexs/percolator.ex deleted file mode 100644 index 5613b0c..0000000 --- a/lib/tirexs/percolator.ex +++ /dev/null @@ -1,56 +0,0 @@ -defmodule Tirexs.Percolator do - @moduledoc false - - use Tirexs.DSL.Logic - alias Tirexs.{HTTP} - - - @doc false - defmacro percolator([do: block]) do - extract(block) - end - - @doc false - defmacro percolator(options, [do: block]) do - [options, index_opts] = Tirexs.Search.extract_index_options(options) - extract(block) ++ options ++ index_opts - end - - - alias Tirexs.Query - - @doc false - def transpose(block) do - case block do - {:query, _, [params]} -> Query._query(params[:do]) - {:query, _, options} -> Query._query(options) - {:doc, _, [params]} -> doc(params[:do]) - {:doc, _, options} -> doc(options) - end - end - - @doc false - def doc(options, doc_opts \\ []) do - options = List.first(extract_block(options)) - [doc: extract_block(options) ++ doc_opts] - end - - @doc false - def create_resource(definition, uri \\ Tirexs.get_uri_env()) do - Tirexs.bump(definition, uri).percolator(definition[:index], definition[:name]) - end - - @doc false - def to_resource_json(definition) do - definition = Keyword.delete(definition, :index) - definition = Keyword.delete(definition, :type) - definition = Keyword.delete(definition, :name) - - HTTP.encode(definition) - end - - @doc false - def match(definition, uri \\ Tirexs.get_uri_env()) do - Tirexs.bump(definition, uri)._percolate(definition[:index], definition[:type]) - end -end diff --git a/lib/tirexs/resources.ex b/lib/tirexs/resources.ex index 93cd506..f2b0d52 100644 --- a/lib/tirexs/resources.ex +++ b/lib/tirexs/resources.ex @@ -50,7 +50,7 @@ defmodule Tirexs.Resources do @doc false def normalize(resource) when is_binary(resource) do - String.strip(resource) |> String.replace_prefix("/", "") + String.trim(resource) |> String.replace_prefix("/", "") end def normalize({ params }) do "?" <> URI.encode_query(params) diff --git a/lib/tirexs/resources/apis.ex b/lib/tirexs/resources/apis.ex index ebcf143..7019ab4 100644 --- a/lib/tirexs/resources/apis.ex +++ b/lib/tirexs/resources/apis.ex @@ -81,10 +81,6 @@ defmodule Tirexs.Resources.APIs do defdelegate _search_shards(a,b), to: Search defdelegate _search_shards(a,b,c), to: Search - defdelegate _field_stats(), to: Search - defdelegate _field_stats(a), to: Search - defdelegate _field_stats(a,b), to: Search - defdelegate _validate_query(), to: Search defdelegate _validate_query(a), to: Search defdelegate _validate_query(a,b), to: Search @@ -110,19 +106,6 @@ defmodule Tirexs.Resources.APIs do defdelegate _search_scroll_all(), to: Search - defdelegate percolator(a,b), to: Search - - defdelegate _percolate(a), to: Search - defdelegate _percolate(a,b), to: Search - defdelegate _percolate(a,b,c), to: Search - defdelegate _percolate(a,b,c,d), to: Search - - defdelegate _percolate_count(a), to: Search - defdelegate _percolate_count(a,b), to: Search - defdelegate _percolate_count(a,b,c), to: Search - defdelegate _percolate_count(a,b,c,d), to: Search - - alias Tirexs.Resources.Indices ## Mapping Management @@ -145,11 +128,6 @@ defmodule Tirexs.Resources.APIs do defdelegate _analyze(a,b), to: Indices defdelegate _analyze(a,b,c), to: Indices - defdelegate _warmer(), to: Indices - defdelegate _warmer(a), to: Indices - defdelegate _warmer(a,b), to: Indices - defdelegate _warmer(a,b,c), to: Indices - defdelegate _template(), to: Indices defdelegate _template(a), to: Indices defdelegate _template(a,b), to: Indices diff --git a/lib/tirexs/resources/indices.ex b/lib/tirexs/resources/indices.ex index 6256040..8de89fe 100644 --- a/lib/tirexs/resources/indices.ex +++ b/lib/tirexs/resources/indices.ex @@ -37,14 +37,6 @@ defmodule Tirexs.Resources.Indices do def _analyze(a), do: __c(urn(a, @r[:action]), @r) def _analyze(), do: __c(urn(@r[:action]), @r) - @doc false - @r [action: "/_warmer", bump: :put, bump!: :put!] - def _warmer(a, b, c), do: __c(urn(a, @r[:action], b, c), @r) - def _warmer(a, b), do: __c(urn(a, @r[:action], b), @r) - def _warmer({a}), do: __c(urn(@r[:action], {a}), @r) - def _warmer(a), do: __c(urn(a, @r[:action]), @r) - def _warmer(), do: __c(urn(@r[:action]), @r) - @doc false @r [action: "/_template", bump: :put, bump!: :put!] def _template(a, b, c), do: __c(urn(a, @r[:action], b, c), @r) diff --git a/lib/tirexs/resources/search.ex b/lib/tirexs/resources/search.ex index 74507e0..781c42c 100644 --- a/lib/tirexs/resources/search.ex +++ b/lib/tirexs/resources/search.ex @@ -18,13 +18,6 @@ defmodule Tirexs.Resources.Search do def _search_shards(a, b), do: __c(urn([a, b, @r[:action]]), @r) def _search_shards(a), do: __c(urn([a, @r[:action]]), @r) - @doc false - @r [action: "/_field_stats", bump: :post, bump!: :post!] - def _field_stats(a, b), do: __c(urn([a, @r[:action], b]), @r) - def _field_stats({a}), do: __c(urn([@r[:action], {a}]), @r) - def _field_stats(a), do: __c(urn([a, @r[:action]]), @r) - def _field_stats(), do: __c(urn([@r[:action]]), @r) - @doc false @r [action: "/_validate/query", bump: :post, bump!: :post!] def _validate_query(a, b, c), do: __c(urn([a, b, @r[:action], c]), @r) @@ -69,26 +62,4 @@ defmodule Tirexs.Resources.Search do @doc false @r [action: "/_search/scroll/_all", bump: :delete, bump!: :delete!] def _search_scroll_all(), do: __c(urn([@r[:action]]), @r) - - @doc false - @r [action: "/.percolator", bump: :put, bump!: :put!] - def percolator(a,b), do: __c(urn([a, @r[:action], b]), @r) - - @doc false - @r [action: "/_percolate", bump: :post, bump!: :post!] - def _percolate(a), do: __c(urn([a, @r[:action]]), @r) - def _percolate(a, {b}), do: __c(urn([a, @r[:action], {b}]), @r) - def _percolate(a, b), do: __c(urn([a, b, @r[:action]]), @r) - def _percolate(a, b, {c}), do: __c(urn([a, b, @r[:action], {c}]), @r) - def _percolate(a, b, c), do: __c(urn([a, b, c, @r[:action]]), @r) - def _percolate(a, b, c, d), do: __c(urn([a, b, c, @r[:action], d]), @r) - - @doc false - @r [action: "/_percolate/count", bump: :post, bump!: :post!] - def _percolate_count(a), do: __c(urn([a, @r[:action]]), @r) - def _percolate_count(a, {b}), do: __c(urn([a, @r[:action], {b}]), @r) - def _percolate_count(a, b), do: __c(urn([a, b, @r[:action]]), @r) - def _percolate_count(a, b, {c}), do: __c(urn([a, b, @r[:action], {c}]), @r) - def _percolate_count(a, b, c), do: __c(urn([a, b, c, @r[:action]]), @r) - def _percolate_count(a, b, c, d), do: __c(urn([a, b, c, @r[:action], d]), @r) end diff --git a/lib/tirexs/search/warmer.ex b/lib/tirexs/search/warmer.ex deleted file mode 100644 index af310c7..0000000 --- a/lib/tirexs/search/warmer.ex +++ /dev/null @@ -1,54 +0,0 @@ -defmodule Tirexs.Search.Warmer do - @moduledoc false - - use Tirexs.DSL.Logic - - - defmacro warmers([do: block]) do - [warmers: extract(block)] - end - - - alias Tirexs.{Query, Query.Filter, Search.Aggs} - - def transpose(block) do - case block do - {:filter, _, [params]} -> Filter._filter(params[:do]) - {:query, _, [params]} -> Query._query(params[:do]) - {:aggs, _, [params]} -> Aggs._aggs(params[:do]) - {name, _, [params]} -> make_warmer(name, params[:do]) - {name, _, params} -> make_warmer(name, params) - end - end - - def make_warmer(name, options, warmers_opts \\ []) - - def make_warmer(name, options, _warmers_opts) when is_list(options) do - warmers_opts = extract_do(options, 1) - options = Enum.fetch!(options, 0) - Keyword.put([], to_atom(name), routers(name, warmers_opts, []) ++ options) - end - - def make_warmer(name, options, warmers_opts) do - Keyword.put([], to_atom(name), routers(name, options, []) ++ warmers_opts) - end - - def source(options, source_opts \\ []) - - def source(options, _source_opts) when is_list(options) do - source_opts = extract_do(options, 1) - options = Enum.fetch!(options, 0) - [source: extract(source_opts) ++ options] - end - - def source(options, source_opts) do - [source: extract(options) ++ source_opts] - end - - defp routers(name, options, add_options) do - case options do - {:source, _, [params]} -> source(params[:do]) - options -> Keyword.put([], to_atom(name), extract(options) ++ add_options) - end - end -end diff --git a/test/acceptances/examples_test.exs b/test/acceptances/examples_test.exs index 3d50160..f57b8e1 100644 --- a/test/acceptances/examples_test.exs +++ b/test/acceptances/examples_test.exs @@ -29,8 +29,4 @@ defmodule Acceptances.ExamplesTest do test ~S(loads "examples/search.exs") do Path.expand("examples/search.exs") |> Tirexs.load_file end - - test ~S(loads "examples/percolator.exs") do - Path.expand("examples/percolator.exs") |> Tirexs.load_file - end end diff --git a/test/acceptances/mapping_test.exs b/test/acceptances/mapping_test.exs index 73ef9f0..ca55615 100644 --- a/test/acceptances/mapping_test.exs +++ b/test/acceptances/mapping_test.exs @@ -39,7 +39,7 @@ defmodule Acceptances.MappingTest do test "create mapping and settings" do HTTP.delete("articles") - index = [index: "articles", type: "article"] + index = [index: "articles", type: "_doc"] settings do analysis do analyzer "autocomplete_analyzer", @@ -50,15 +50,15 @@ defmodule Acceptances.MappingTest do filter "edge_ngram", [type: "edgeNGram", min_gram: 1, max_gram: 15] end end - mappings dynamic: "false", _parent: [type: "parent"] do - indexes "country", type: "string" - indexes "city", type: "string" - indexes "suburb", type: "string" - indexes "road", type: "string" - indexes "postcode", type: "string", index: "not_analyzed" - indexes "housenumber", type: "string", index: "not_analyzed" + mappings dynamic: "false" do + indexes "country", type: "text" + indexes "city", type: "text" + indexes "suburb", type: "text" + indexes "road", type: "text" + indexes "postcode", type: "text" + indexes "housenumber", type: "text" indexes "coordinates", type: "geo_point" - indexes "full_address", type: "string", analyzer: "autocomplete_analyzer" + indexes "full_address", type: "text", analyzer: "autocomplete_analyzer" end Tirexs.Mapping.create_resource(index) @@ -74,8 +74,8 @@ defmodule Acceptances.MappingTest do assert %{analyzer: %{autocomplete_analyzer: %{filter: ["lowercase", "asciifolding", "edge_ngram"], tokenizer: "whitespace"}}, filter: %{edge_ngram: %{max_gram: "15", min_gram: "1", type: "edgeNGram"}}} == analyzer - %{article: properties} = mappings + %{_doc: properties} = mappings - assert %{dynamic: "false", _parent: %{type: "parent"}, _routing: %{required: true}, properties: %{city: %{type: "string"}, coordinates: %{type: "geo_point"}, country: %{type: "string"}, full_address: %{analyzer: "autocomplete_analyzer", type: "string"}, housenumber: %{index: "not_analyzed", type: "string"}, postcode: %{index: "not_analyzed", type: "string"}, road: %{type: "string"}, suburb: %{type: "string"}}} == properties + assert %{dynamic: "false", properties: %{city: %{type: "text"}, coordinates: %{type: "geo_point"}, country: %{type: "text"}, full_address: %{analyzer: "autocomplete_analyzer", type: "text"}, housenumber: %{type: "text"}, postcode: %{type: "text"}, road: %{type: "text"}, suburb: %{type: "text"}}} == properties end end diff --git a/test/acceptances/percolator_test.exs b/test/acceptances/percolator_test.exs deleted file mode 100644 index fad94c1..0000000 --- a/test/acceptances/percolator_test.exs +++ /dev/null @@ -1,41 +0,0 @@ -defmodule Tirexs.PercolatorTest do - use ExUnit.Case - - import Tirexs.Bulk - import Tirexs.Percolator - - alias Tirexs.{HTTP, Percolator} - - - setup do - HTTP.delete("my-index") && :ok - # HTTP.delete("my-index/.percolator/1") && :ok - end - - test :percolator do - payload = bulk([index: "my-index", type: "my-type"]) do - create [ - [ id: 1, message: "foo bar test" ], - [ id: 2, message: "bar bar test" ], - [ id: 3, message: "Old bonsai tree is down" ] - ] - end - Tirexs.bump(payload)._bulk({ [refresh: true] }) - - percolator = percolator([index: "my-index", name: 1]) do - query do - match "message", "bonsai tree" - end - end - { _, _, %{created: created} } = Percolator.create_resource(percolator) - assert created - - percolator = percolator([index: "my-index", type: "message"]) do - doc do - [[message: "A new bonsai tree in the office"]] - end - end - { _, _, %{total: total} } = Percolator.match(percolator) - assert total == 1 - end -end diff --git a/test/acceptances/resources/search_test.exs b/test/acceptances/resources/search_test.exs index 38b1180..79f03e5 100644 --- a/test/acceptances/resources/search_test.exs +++ b/test/acceptances/resources/search_test.exs @@ -40,16 +40,6 @@ defmodule Acceptances.Resources.SearchTest do { :ok, 200, _ } = Resources.bump._search_shards("bear_test", { [local: true] }) end - test "_field_stats/0" do - { :ok, 200, _ } = HTTP.put("/bear_test") - { :ok, 200, _ } = Resources.bump([fields: ["rating"]])._field_stats() - end - - test "_field_stats/2" do - { :ok, 200, _ } = HTTP.put("/bear_test") - { :ok, 200, _ } = Resources.bump._field_stats("bear_test", { [fields: "some"] }) - end - test "_validate_query/2" do { :ok, 201, _ } = HTTP.put("/bear_test/my_type/1?refresh=true", [user: "kimchy"]) { :ok, 200, r } = Resources.bump._validate_query("bear_test", { [q: "user1:z*"] }) @@ -68,16 +58,12 @@ defmodule Acceptances.Resources.SearchTest do import Tirexs.Query, only: :macros query = query do - filtered do - query do - query_string "*:*" - end - filter do + bool do + must do term "user", "kimchy" end end end - { :ok, 200, r } = Resources.bump(query)._validate_query("bear_test") assert r[:valid] end @@ -89,13 +75,6 @@ defmodule Acceptances.Resources.SearchTest do assert r[:count] == 1 end - test "_search_exists/2" do - { :ok, 201, _ } = HTTP.put("/bear_test/my_type/2?refresh=true", [user: "zatvobor"]) - search = [query: [ term: [ user: "zatvobor" ] ]] - { :ok, 200, r } = Resources.bump(search)._search_exists("bear_test", "my_type") - assert r[:exists] - end - test "_search/2" do { :ok, 201, _ } = HTTP.put("/bear_test/my_type/2?refresh=true", [user: "zatvobor"]) search = [query: [ term: [ user: "zatvobor" ] ]] diff --git a/test/acceptances/warmer_test.exs b/test/acceptances/warmer_test.exs deleted file mode 100644 index e89e161..0000000 --- a/test/acceptances/warmer_test.exs +++ /dev/null @@ -1,36 +0,0 @@ -defmodule Acceptances.WarmerTest do - use ExUnit.Case - - - alias Tirexs.{HTTP} - - - setup do - HTTP.delete("bear_test") && :ok - end - - import Tirexs.Search.Warmer - - test "index warmers" do - warmers = warmers do - warmer_1 [types: []] do - source do - query do - match_all - end - aggs do - agg_name do - terms [field: "gender"] - end - end - end - end - end - - HTTP.put!("bear_test", warmers) - {:ok, 200, %{bear_test: %{warmers: %{warmer_1: actual }}}} = HTTP.get("bear_test/_warmer/warmer_1") - - expected = %{source: %{aggs: %{agg_name: %{terms: %{field: "gender"}}}, query: %{match_all: []}}, types: []} - assert actual == expected - end -end diff --git a/test/tirexs/http_test.exs b/test/tirexs/http_test.exs index 13f94b5..774f97e 100644 --- a/test/tirexs/http_test.exs +++ b/test/tirexs/http_test.exs @@ -140,7 +140,7 @@ defmodule Tirexs.HTTPTest do @body ~S'{"hello":"world"}' test "decode/1 #{byte_size(@body)} bytes string" do - actual = decode(to_char_list(@body)) + actual = decode(to_charlist(@body)) assert actual == %{hello: "world"} end diff --git a/test/tirexs/index/settings/analyzer_test.exs b/test/tirexs/index/settings/analyzer_test.exs index 3496eb2..018a3b3 100644 --- a/test/tirexs/index/settings/analyzer_test.exs +++ b/test/tirexs/index/settings/analyzer_test.exs @@ -16,7 +16,7 @@ defmodule Tirexs.Index.Settings.AnalyzerTest do end end - expected = [analysis: [analyzer: [msg_search_analyzer: [tokenizer: "keyword", filter: ["lowercase"]], msg_index_analyzer: [tokenizer: "keyword", filter: ["lowercase","substring"]]]], index: []] + expected = [analysis: [analyzer: [msg_search_analyzer: [tokenizer: "keyword", filter: ["lowercase"]], msg_index_analyzer: [tokenizer: "keyword", filter: ["lowercase","substring"]]]]] assert index[:settings] == expected end end diff --git a/test/tirexs/index/settings/blocks_test.exs b/test/tirexs/index/settings/blocks_test.exs index 1fbdf22..90c9b05 100644 --- a/test/tirexs/index/settings/blocks_test.exs +++ b/test/tirexs/index/settings/blocks_test.exs @@ -13,7 +13,7 @@ defmodule Tirexs.Index.Settings.BlocksTest do blocks read_only: true, read: true, write: false, metadata: true end - expected = [index: [blocks: [read_only: true, read: true, write: false, metadata: true]]] + expected = [blocks: [read_only: true, read: true, write: false, metadata: true]] assert index[:settings] == expected end end diff --git a/test/tirexs/index/settings/cache_test.exs b/test/tirexs/index/settings/cache_test.exs index 81b5eeb..2285d97 100644 --- a/test/tirexs/index/settings/cache_test.exs +++ b/test/tirexs/index/settings/cache_test.exs @@ -13,7 +13,7 @@ defmodule Tirexs.Index.Settings.CacheTest do cache max_size: -1, expire: -1 end - expected = [index: [cache: [filter: [max_size: -1, expire: -1]]]] + expected = [cache: [filter: [max_size: -1, expire: -1]]] assert index[:settings] == expected end end diff --git a/test/tirexs/index/settings/filter_test.exs b/test/tirexs/index/settings/filter_test.exs index 628521f..968b3ec 100644 --- a/test/tirexs/index/settings/filter_test.exs +++ b/test/tirexs/index/settings/filter_test.exs @@ -16,7 +16,7 @@ defmodule Tirexs.Index.Settings.FilterTest do end end - expected = [analysis: [filter: [substring: [type: "nGram", min_gram: 2, max_gram: 32], snow_en: [type: "snowball", language: "English"]]], index: []] + expected = [analysis: [filter: [substring: [type: "nGram", min_gram: 2, max_gram: 32], snow_en: [type: "snowball", language: "English"]]]] assert index[:settings] == expected end end diff --git a/test/tirexs/index/settings/set_test.exs b/test/tirexs/index/settings/set_test.exs index 11dc398..3857afa 100644 --- a/test/tirexs/index/settings/set_test.exs +++ b/test/tirexs/index/settings/set_test.exs @@ -13,7 +13,7 @@ defmodule Tirexs.Index.Settings.SetTest do set number_of_replicas: 3, auto_expand_replicas: 5 end - expected = [index: [number_of_replicas: 3, auto_expand_replicas: 5]] + expected = [number_of_replicas: 3, auto_expand_replicas: 5] assert index[:settings] == expected end end diff --git a/test/tirexs/index/settings/tokenizer_test.exs b/test/tirexs/index/settings/tokenizer_test.exs index e27b452..390f368 100644 --- a/test/tirexs/index/settings/tokenizer_test.exs +++ b/test/tirexs/index/settings/tokenizer_test.exs @@ -15,7 +15,7 @@ defmodule Tirexs.Index.Settings.TokenizerTest do end end - expected = [analysis: [tokenizer: ["dot-tokenizer": [type: "path_hierarchy", delimiter: "."]]], index: []] + expected = [analysis: [tokenizer: ["dot-tokenizer": [type: "path_hierarchy", delimiter: "."]]]] assert index[:settings] == expected end end diff --git a/test/tirexs/index/settings/translog_test.exs b/test/tirexs/index/settings/translog_test.exs deleted file mode 100644 index 97d8b69..0000000 --- a/test/tirexs/index/settings/translog_test.exs +++ /dev/null @@ -1,22 +0,0 @@ -Code.require_file "../../../../test_helper.exs", __ENV__.file - -defmodule Tirexs.Index.Settings.TranslogTest do - use ExUnit.Case - - import Tirexs.Index.Settings - - - test "settings w/ translog" do - index = [name: "bear_test"] - - settings do - translog flush_threshold_ops: "", - flush_threshold_size: 2002, - flush_threshold_period: 1, - disable_flush: true - end - - expected = [index: [translog: [flush_threshold_ops: "", flush_threshold_size: 2002, flush_threshold_period: 1, disable_flush: true]]] - assert index[:settings] == expected - end -end diff --git a/test/tirexs/index/settings_test.exs b/test/tirexs/index/settings_test.exs index e9d832f..fac093a 100644 --- a/test/tirexs/index/settings_test.exs +++ b/test/tirexs/index/settings_test.exs @@ -16,7 +16,7 @@ defmodule Tirexs.Index.SettingsTest do cache [] end - expected = [analysis: [], index: [cache: [filter: []], translog: [], blocks: []]] + expected = [cache: [filter: []], translog: [], blocks: [], analysis: []] assert index[:settings] == expected end @@ -37,7 +37,7 @@ defmodule Tirexs.Index.SettingsTest do blocks write: true end - expected = [analysis: [tokenizer: ["dot-tokenizer": [type: "path_hierarchy", delimiter: "."]], filter: [substring: [type: "nGram", min_gram: 2, max_gram: 32]], analyzer: [msg_search_analyzer: [tokenizer: "keyword", filter: ["lowercase"]], msg_index_analyzer: [tokenizer: "keyword", filter: ["lowercase","substring"]]]], index: [blocks: [write: true], translog: [disable_flush: false], cache: [filter: [max_size: -1]], number_of_replicas: 3]] + expected = [blocks: [write: true], translog: [disable_flush: false], cache: [filter: [max_size: -1]], analysis: [tokenizer: ["dot-tokenizer": [type: "path_hierarchy", delimiter: "."]], filter: [substring: [type: "nGram", min_gram: 2, max_gram: 32]], analyzer: [msg_search_analyzer: [tokenizer: "keyword", filter: ["lowercase"]], msg_index_analyzer: [tokenizer: "keyword", filter: ["lowercase", "substring"]]]], number_of_replicas: 3] assert index[:settings] == expected end end diff --git a/test/tirexs/mapping_test.exs b/test/tirexs/mapping_test.exs index b4b44d2..4ee410d 100644 --- a/test/tirexs/mapping_test.exs +++ b/test/tirexs/mapping_test.exs @@ -197,7 +197,7 @@ defmodule Tirexs.MappingsTest do expected = [properties: [id: [type: "multi_field", fields: [name_en: [type: "string", analyzer: "analyzer_en", boost: 100], exact: [type: "string", index: "not_analyzed"]]], title: [type: "string"]]] assert index[:mapping] == expected - expected = [analysis: [analyzer: [autocomplete_analyzer: [filter: ["icu_normalizer", "icu_folding", "edge_ngram"], tokenizer: "icu_tokenizer"]], filter: [edge_ngram: [type: "edgeNGram", min_gram: 1, max_gram: 15]]], index: []] + expected = [analysis: [analyzer: [autocomplete_analyzer: [filter: ["icu_normalizer", "icu_folding", "edge_ngram"], tokenizer: "icu_tokenizer"]], filter: [edge_ngram: [type: "edgeNGram", min_gram: 1, max_gram: 15]]]] assert index[:settings] == expected end end diff --git a/test/tirexs/percolator_test.exs b/test/tirexs/percolator_test.exs deleted file mode 100644 index 4d77bfd..0000000 --- a/test/tirexs/percolator_test.exs +++ /dev/null @@ -1,44 +0,0 @@ -Code.require_file "../../test_helper.exs", __ENV__.file - -defmodule Tirexs.PerlocatorTest do - use ExUnit.Case - - import Tirexs.Percolator - - - test "percolator query in general" do - percolator = percolator do - query do - term "field1", "value1" - end - end - - expected = [query: [term: [field1: "value1"]]] - assert percolator == expected - end - - test "percolator query w/ options" do - percolator = percolator [color: "blue"] do - query do - term "field1", "value1" - end - end - - expected = [query: [term: [field1: "value1"]], color: "blue"] - assert percolator == expected - end - - test "percolator query w/ doc" do - percolator = percolator do - doc do - [[field1: "value1"]] - end - query do - term "field1", "value1" - end - end - - expected = [doc: [field1: "value1"], query: [term: [field1: "value1"]]] - assert percolator == expected - end -end diff --git a/test/tirexs/resources/indices_test.exs b/test/tirexs/resources/indices_test.exs index 0ea2e41..b8f6ebe 100644 --- a/test/tirexs/resources/indices_test.exs +++ b/test/tirexs/resources/indices_test.exs @@ -7,7 +7,7 @@ defmodule Tirexs.Resources.IndicesTest do @resources [ "_refresh", "_flush", "_forcemerge", "_upgrade", "_alias", "_aliases", "_stats", "_segments", "_recovery", "_shard_stores", "_close", "_open", - "_analyze", "_warmer", "_template", "_settings", + "_analyze", "_template", "_settings", "_mapping" ] diff --git a/test/tirexs/resources/search_test.exs b/test/tirexs/resources/search_test.exs index f3972d9..25da0b8 100644 --- a/test/tirexs/resources/search_test.exs +++ b/test/tirexs/resources/search_test.exs @@ -34,16 +34,6 @@ defmodule Tirexs.Resources.SearchTest do assert actual == "twitter/tweet/_search_shards" end - test ~S| functions like a '_field_stats(["index1", "index2"])' | do - actual = Search._field_stats(["index1", "index2"]) - assert actual == "index1,index2/_field_stats" - end - - test ~S| functions like a '_field_stats("bear_test", { [fields: "rating"] })' | do - actual = Search._field_stats("bear_test", { [fields: "rating"] }) - assert actual == "bear_test/_field_stats?fields=rating" - end - test ~S| functions like a '_validate_query("twitter")' | do actual = Search._validate_query("twitter") assert actual == "twitter/_validate/query" @@ -158,69 +148,4 @@ defmodule Tirexs.Resources.SearchTest do actual = Search._search_scroll_all() assert actual == "_search/scroll/_all" end - - test ~S| functions like a 'percolator("twitter", "1")' | do - actual = Search.percolator("twitter", "1") - assert actual == "twitter/.percolator/1" - end - - test ~S| functions like a '_percolate("twitter/tweet/1")' | do - actual = Search._percolate("twitter/tweet/1") - assert actual == "twitter/tweet/1/_percolate" - end - - test ~S| functions like a '_percolate("twitter/tweet/1", { [ignore_unavailable: true] })' | do - actual = Search._percolate("twitter/tweet/1", { [ignore_unavailable: true] }) - assert actual == "twitter/tweet/1/_percolate?ignore_unavailable=true" - end - - test ~S| functions like a '_percolate("twitter", "tweet")' | do - actual = Search._percolate("twitter", "tweet") - assert actual == "twitter/tweet/_percolate" - end - - test ~S| functions like a '_percolate("twitter", "tweet", { [ignore_unavailable: true] })' | do - actual = Search._percolate("twitter", "tweet", { [ignore_unavailable: true] }) - assert actual == "twitter/tweet/_percolate?ignore_unavailable=true" - end - - test ~S| functions like a '_percolate("twitter", "tweet", 1)' | do - actual = Search._percolate("twitter", "tweet", 1) - assert actual == "twitter/tweet/1/_percolate" - end - - test ~S| functions like a '_percolate("twitter", "tweet", 1, { [ignore_unavailable: true] })' | do - actual = Search._percolate("twitter", "tweet", 1, { [ignore_unavailable: true] }) - assert actual == "twitter/tweet/1/_percolate?ignore_unavailable=true" - end - - test ~S| functions like a '_percolate_count("twitter/tweet/1")' | do - actual = Search._percolate_count("twitter/tweet/1") - assert actual == "twitter/tweet/1/_percolate/count" - end - - test ~S| functions like a '_percolate_count("twitter/tweet/1", { [ignore_unavailable: true] })' | do - actual = Search._percolate_count("twitter/tweet/1", { [ignore_unavailable: true] }) - assert actual == "twitter/tweet/1/_percolate/count?ignore_unavailable=true" - end - - test ~S| functions like a '_percolate_count("twitter", "tweet")' | do - actual = Search._percolate_count("twitter", "tweet") - assert actual == "twitter/tweet/_percolate/count" - end - - test ~S| functions like a '_percolate_count("twitter", "tweet", { [ignore_unavailable: true] })' | do - actual = Search._percolate_count("twitter", "tweet", { [ignore_unavailable: true] }) - assert actual == "twitter/tweet/_percolate/count?ignore_unavailable=true" - end - - test ~S| functions like a '_percolate_count("twitter", "tweet", 1)' | do - actual = Search._percolate_count("twitter", "tweet", 1) - assert actual == "twitter/tweet/1/_percolate/count" - end - - test ~S| functions like a '_percolate_count("twitter", "tweet", 1, { [ignore_unavailable: true] })' | do - actual = Search._percolate_count("twitter", "tweet", 1, { [ignore_unavailable: true] }) - assert actual == "twitter/tweet/1/_percolate/count?ignore_unavailable=true" - end end diff --git a/test/tirexs/search/sort_test.exs b/test/tirexs/search/sort_test.exs index 5f22fcd..c885e6a 100644 --- a/test/tirexs/search/sort_test.exs +++ b/test/tirexs/search/sort_test.exs @@ -34,7 +34,7 @@ defmodule Tirexs.Search.SortTest do test "sort w/ _geo_distance_sort" do sort = sort do [ - "_geo_distance": ["pin.location": [-70, 40], order: "asc", unit: "km"] + _geo_distance: ["pin.location": [-70, 40], order: "asc", unit: "km"] ] end diff --git a/test/tirexs/search/warmer_test.exs b/test/tirexs/search/warmer_test.exs deleted file mode 100644 index edefa35..0000000 --- a/test/tirexs/search/warmer_test.exs +++ /dev/null @@ -1,26 +0,0 @@ -defmodule Tirexs.Search.WarmerTest do - use ExUnit.Case - - import Tirexs.Search.Warmer - - - test "index warmers" do - warmers = warmers do - warmer_1 [types: []] do - source do - query do - term "user", "kim" - end - aggs do - aggs_name do - terms [field: "tag", size: 10, order: "term"] - end - end - end - end - end - - expected = [warmers: [warmer_1: [source: [query: [term: [user: "kim"]], aggs: [aggs_name: [terms: [field: "tag", size: 10, order: "term"]]]], types: []]]] - assert warmers == expected - end -end