Skip to content

Instantly share code, notes, and snippets.

@rafaltrojanowski
Last active January 12, 2022 12:56
Show Gist options
  • Save rafaltrojanowski/1e678dcf39a1591c3b407cc091cd687b to your computer and use it in GitHub Desktop.
Save rafaltrojanowski/1e678dcf39a1591c3b407cc091cd687b to your computer and use it in GitHub Desktop.
indexing issue
Bastion:
a1 = Domain.Repo.get_by(Domain.Answer, id: 555)
query = %{"query" => %{"terms" => %{"_id" => [a1.id]}}}
query |> Domain.Elasticsearch.search("answers_dev5")
{:ok,
%{
"_shards" => %{
"failed" => 0,
"skipped" => 0,
"successful" => 1,
"total" => 1
},
"hits" => %{
"hits" => [
%{
"_id" => "555",
"_index" => "answers_dev5",
"_score" => 1.0,
"_source" => %{
"additional_answers" => [],
"comment" => "Karton wurde vom Paketdienst sicher geworfen.",
"comment_de_DE" => "Karton wurde vom Paketdienst sicher geworfen.",
"has_comment" => true,
"id" => 555,
"inserted_at" => "2021-06-08T09:31:32Z",
"is_a_test" => false,
"label_ids" => [9500],
"language" => "de_DE",
"language_id" => 75,
"properties" => [],
"public_hash_id" => "TXpZeFlUZGlaVFV0T1RRME5TMDBNV1EwTFRnNVpHWXRNakE1WWpGaE1USXlZV1Zr",
"recipient_full_name" => nil,
"recipient_id" => nil,
"recipient_identity" => nil,
"recipient_identity_type" => nil,
"recipient_upload_method" => nil,
"score" => 9,
"score_type" => "promoter",
"sentiment" => "positive",
"sentiment_per_label" => [],
"stripped_comment" => "Karton wurd Paketdien sich geworf",
"survey_id" => 12,
"survey_recipient_id" => nil,
"translated_comment" => nil,
"translated_language_id" => nil,
"updated_at" => "2021-11-26T10:28:13Z"
},
"_type" => "_doc"
}
],
"max_score" => 1.0,
"total" => %{"relation" => "eq", "value" => 1}
},
"timed_out" => false,
"took" => 1
}}
@rafaltrojanowski
Copy link
Author

Problems:

  • Uglu formating of responses
  • Problems with copy pastying long json body
  • Solution Kibana, but yes I prefer to use hammer!

@rafaltrojanowski
Copy link
Author

rafaltrojanowski commented Jan 12, 2022

For dev2 whe have:
answers_dev2_v3

Steps that I've done:

Read Json from file:

defmodule JsonToMap do
  def get_json(filename) do
    with {:ok, body} <- File.read(filename),
         {:ok, json} <- Poison.decode(body), do: {:ok, json}
  end
end

#how to access file from from bastion
template_map = JsonToMap.get_json("/Users/rafaltrojanowski/Projects/Zenloop/backend/apps/domain/priv/indexes/answers.json")

body = %{
  "index_patterns": [
    "answers",
    "answers*"
  ],
  "template": template_map
}
{:ok, response} = Domain.Env.get(:elasticsearch_url) |> URI.merge("/_index_template/answers_template/_mapping?pretty") |> URI.to_string() |> Elastix.HTTP.put()


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment