Skip to content

Commit

Permalink
Merge pull request #286 from Zatvobor/6.6.2
Browse files Browse the repository at this point in the history
support 6.6.2 ES
  • Loading branch information
OpakAlex authored Feb 19, 2020
2 parents 1487b40 + 9312b54 commit 6282ab4
Show file tree
Hide file tree
Showing 34 changed files with 71 additions and 532 deletions.
21 changes: 3 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
26 changes: 0 additions & 26 deletions examples/percolator.exs

This file was deleted.

5 changes: 0 additions & 5 deletions examples/settings.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions lib/tirexs/dsl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
6 changes: 3 additions & 3 deletions lib/tirexs/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 27 additions & 1 deletion lib/tirexs/index/logic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -28,14 +44,24 @@ 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
def add_index_setting(index, main_type, type, value) 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))
Expand Down
15 changes: 7 additions & 8 deletions lib/tirexs/index/settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
56 changes: 0 additions & 56 deletions lib/tirexs/percolator.ex

This file was deleted.

2 changes: 1 addition & 1 deletion lib/tirexs/resources.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 0 additions & 22 deletions lib/tirexs/resources/apis.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 0 additions & 8 deletions lib/tirexs/resources/indices.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 6282ab4

Please sign in to comment.