Not able to populate @timestamp value to a table in html file


(vivek) #1

I'm trying to populate @timestamp value to a table using the following code.

// $(row).html(item._source.message);
$(row).html(item._source._timestamp);
this is not working
but other fields apart from @timestamp we are able to populate to the table
Do you know how to populate @timestamp value to table.

Please help me in how we can do this.

We are quering the @timestamp value using moustache file from elastic search.


(Shaunak Kashyap) #2

Have you tried item.source.@timestamp or item.source['@timestamp']?


(vivek) #3

Yes, we have tried both that is giving syntax error.
item._source.@timestamp or item._source['@timestamp']?

But // $(row).html(item._source.message); is working .


(Shaunak Kashyap) #4

Can you share the syntax error?

Also, just for debugging purposes, can you output the entirety of item._source and paste it here?


(vivek) #5

Please find the syntax error

Uncaught SyntaxError: Unexpected token ILLEGAL

Code:
resp.hits.hits.forEach( function(item) {
var row = "#srchres table tr:nth-child("+i+") td:nth-child(2)";
$(row).html(item._source.@timestamp);
// $(row).html(item._source.message);
// $(row).html( item._source['@timestamp']);
i++;
});

Please find the item._source

{
"_index": "logstash-2016.01.05",
"_type": "logs",
"_id": "AVIQkVhZdgDuKuS_rjvC",
"_score": 1.4354146,
"_source": {
"@timestamp": "2016-01-05T06:55:04.189Z",
"message": "2015/11/10 20:48:28 [ERRTEST] /SW2/spanky/i2c-3/FT3: Read Reg 21"
}


(Shaunak Kashyap) #6

Inside the forEach can you do a console.log(item._source) and paste it's output here, please?


(vivek) #7

Please find the output

Object {@timestamp: "2016-01-05T06:55:04.189Z", message: "2015/11/10 20:48:28 [ERRTEST] /SW2/spanky/i2c-3/FT3: Read Reg 21"}


(Shaunak Kashyap) #8

Okay, so that clearly indicates that @timestamp is part of the object. I think this is a jQuery escaping issue. I'm not a jQuery expert but I'd suggest trying to escape the @ character. Maybe try item._source['\\@timestamp'], according to https://api.jquery.com/category/selectors/?


(vivek) #9

Thanks. I've tried thus but getting syntax error. Even i'm learning Jquery.


(system) #10