Skip to content

Commit

Permalink
Merge pull request #3 from surgeventures/fix-doc-as-upsert
Browse files Browse the repository at this point in the history
Fix doc as upsert
  • Loading branch information
Ptrboro authored May 15, 2024
2 parents 65eda7c + e1f8009 commit 3135b2d
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
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

0 comments on commit 3135b2d

Please sign in to comment.