Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 0 additions & 69 deletions .circleci/config.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ elastix-*.tar

# Misc.
tags

.idea/
elastix.iml
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
elixir 1.18.4-otp-28
erlang 28.1.1
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

config :mix_test_watch,
tasks: [
Expand Down
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

config :elastix,
test_url: "http://127.0.0.1:9200",
Expand Down
22 changes: 12 additions & 10 deletions lib/elastix/bulk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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, [])

Expand All @@ -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 """
Expand All @@ -70,25 +74,23 @@ 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
_ -> HTTP.append_query_string(path, query_params)
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
31 changes: 20 additions & 11 deletions lib/elastix/document.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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("/")

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
13 changes: 6 additions & 7 deletions lib/elastix/mapping.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 3 additions & 9 deletions lib/elastix/search.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/elastix/snapshot/repository.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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"])
Expand All @@ -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))
Expand All @@ -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))
Expand Down
22 changes: 16 additions & 6 deletions lib/elastix/snapshot/snapshot.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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"])
Expand All @@ -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"])
Expand All @@ -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))
Expand All @@ -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))
Expand Down
Loading