converting back to list
henry-hz opened this issue · 3 comments
henry-hz commented
Hi there,
pls, let me report what seems to be a bug. the pid and node are going to elastic as numerical list format, even after converting to string.
defmodule Log do
require Timex
@doc """
* module - the module name where this message comes from
* level [critical_error, error, warning, info]
* message - whatever you want
"""
def log(module, level, message) do
time = Timex.format!(Timex.DateTime.now, "{ISO}")
pid = self |> :erlang.pid_to_list |> List.to_string
nod = node |> :erlang.atom_to_list |> List.to_string
IO.inspect pid
IO.inspect nod
Tirexs.HTTP.put("/miner4/users/3", [time: time, level: level, nod: nod, pid: pid, message: message])
#Tirexs.HTTP.put("/miner3/log/2", [time: time, nodes: "nodsdf", pid: "pid", module: module, level: level message: message])
end
end
outputs:
{
"_index": "miner2",
"_type": "log",
"_id": "1",
"_score": 1,
"_source": {
"time": "2016-05-23T07:03:15.897+00:00",
"nod": [
110,
111,
110,
111,
100,
101,
64,
110,
111,
104,
111,
115,
116
],
"pid": [
60,
48,
46,
50,
56,
50,
46,
48,
62
],
"module": "mod",
"level": "warning",
"message": "hai there"
},
"fields": {
"time": [
1463986995897
]
}
}
Zatvobor commented
Hey. Take a look at your output ) especially on fields such as _index
and _type
)))
I'm playing with it for you and what I want to say: tirexs
has not any issues with it.
iex(12)> pid = self |> :erlang.pid_to_list |> List.to_string
"<0.118.0>"
iex(13)> nod = node |> :erlang.atom_to_list |> List.to_string
"nonode@nohost"
iex(14)> Tirexs.HTTP.put("/index/type/1", [pid: pid, node: nod])
{:ok, 201,
%{_id: "1", _index: "index", _shards: %{failed: 0, successful: 1, total: 2},
_type: "type", _version: 1, created: true}}
iex(15)> Tirexs.HTTP.get("/index/type/1")
{:ok, 200,
%{_id: "1", _index: "index",
_source: %{node: "nonode@nohost", pid: "<0.118.0>"}, _type: "type",
_version: 1, found: true}}
➜ tirexs git:(rc) ✗ curl http://127.0.0.1:9200/index/type/1
{"_index":"index","_type":"type","_id":"1","_version":1,"found":true,"_source":{"pid":"<0.118.0>","node":"nonode@nohost"}}%
Let me know if you're still struggling with it.
henry-hz commented
sure, I forgot to describe an important detail, on console it's okay, but on that json, collected from elastic, the list become a sequence of numbers
Zatvobor commented
Ok. Just to make sure.
iex(1)> pid = self |> :erlang.pid_to_list |> List.to_string
"<0.313.0>"
iex(2)> Tirexs.HTTP.put("/index/type/2", [pid: pid])
{:ok, 201,
%{_id: "2", _index: "index", _shards: %{failed: 0, successful: 1, total: 2},
_type: "type", _version: 1, created: true}}
iex(3)> {:ok, _, %{_source: %{pid: pid}}} = Tirexs.HTTP.get("/index/type/2")
{:ok, 200,
%{_id: "2", _index: "index", _source: %{pid: "<0.313.0>"}, _type: "type",
_version: 1, found: true}}
iex(4)> is_binary(pid)
true
Let me know what's wrong here.