Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix doc as upsert #3

Merged
merged 2 commits into from
May 15, 2024
Merged
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
2 changes: 0 additions & 2 deletions lib/snap/bulk/action.ex
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ defimpl Jason.Encoder, for: Snap.Bulk.Action.Update do
%Snap.Bulk.Action.Update{
_index: index,
_id: id,
doc_as_upsert: doc_as_upsert,
require_alias: require_alias,
routing: routing
},
Expand All @@ -133,7 +132,6 @@ defimpl Jason.Encoder, for: Snap.Bulk.Action.Update do
values = [
_index: index,
_id: id,
doc_as_upsert: doc_as_upsert,
require_alias: require_alias,
routing: routing
]
Expand Down
3 changes: 2 additions & 1 deletion lib/snap/bulk/actions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ defmodule Snap.Bulk.Actions do
doc = action.doc

doc_json =
%{doc: doc}
%{doc: doc, doc_as_upsert: action.doc_as_upsert}
|> Map.reject(fn {_key, value} -> is_nil(value) end)
|> Jason.encode!()

action_json = encode_action_command(action)
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Snap.MixProject do

@original_github_url "https://github.com/breakroom/snap"
@github_url "https://github.com/surgeventures/snap"
@version "0.10.2"
@version "0.10.3"

def project do
[
Expand Down
2 changes: 1 addition & 1 deletion test/bulk/actions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ defmodule Snap.Bulk.ActionsTest do
encoded = Actions.encode(actions) |> IO.chardata_to_string()

assert encoded ==
"{\"index\":{\"_index\":\"foo\",\"routing\":\"bar\"}}\n{\"foo\":\"bar\"}\n{\"create\":{\"_index\":\"foo\",\"require_alias\":true,\"routing\":\"bar\"}}\n{\"foo\":\"bar\"}\n{\"update\":{\"_index\":\"foo\",\"_id\":2,\"doc_as_upsert\":true,\"routing\":\"bar\"}}\n{\"doc\":{\"foo\":\"bar\"}}\n{\"delete\":{\"_index\":\"foo\",\"_id\":1,\"routing\":\"bar\"}}\n"
"{\"index\":{\"_index\":\"foo\",\"routing\":\"bar\"}}\n{\"foo\":\"bar\"}\n{\"create\":{\"_index\":\"foo\",\"require_alias\":true,\"routing\":\"bar\"}}\n{\"foo\":\"bar\"}\n{\"update\":{\"_index\":\"foo\",\"_id\":2,\"routing\":\"bar\"}}\n{\"doc\":{\"foo\":\"bar\"},\"doc_as_upsert\":true}\n{\"delete\":{\"_index\":\"foo\",\"_id\":1,\"routing\":\"bar\"}}\n"
end
end
Loading