Kibana - Display times series of tweets posted - Twitter - twitter

I'm using the latest Kibana 4 / ES 1.4 version and I'm trying to display the number of tweets over time. My idea is to slice the 'created_at' field from the tweets documents.
The mapping defined for this field is the following
dynamic_templates": [
{
"created_at": {
"mapping": {
"locale": "US",
"format": "EEE MMM dd HH:mm:ss Z yyyy",
"type": "date"
},
"match": "created_at"
}
},
...
I can create basic charts in Kibana (with term aggregates field) and overall seems to be working but I cannot display any trends with line charts or date histogram .with the created_at field.
Below is the error
ElasticsearchParseException[failed to parse date field [2014-10-13T23:35:31.450Z],
tried both date format [EEE MMM dd HH:mm:ss Z yyyy], and timestamp number]; nested:
IllegalArgumentException[Invalid format: \"2014-10-13T23:35:31.450Z\"]; }
Thanks for your help,
Arnaud

I'm unsure if the format of your date is correct but if it is I had a similar problem in ElasticSearch 1.4 that the parser wouldn't recognise the timestamp unless the timestamp was mapped within properties:
curl -XPUT 'http://localhost:9200/index/container/_mapping' -d'
{
"container" : {
"properties" : {
"#timestamp" : {"type":"date", "format": "dateOptionalTime"}
}
}
}'
Also may not be relavant to you but for a useful article for naming date conventions: http://joelabrahamsson.com/dynamic-mappings-and-dates-in-elasticsearch/
And the elastic search date format list: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-date-format.html
Hope this helps!

Related

What is the correct way to represent dates in a graph database (Neo4j)?

CREATE(:People{name: "Sally", date_of_birth:"12-04-1991"})
I'm confused as to how to find her current age. Is my way of representing a date wrong?
best way is to use the neo4j date / time format : https://neo4j.com/docs/cypher-manual/current/syntax/temporal/
But this should do it, given the date format that you use:
MATCH (p:People {name:"Sally"})
WITH p.date_of_birth AS date_of_birth ,date() AS now
// convert the stringDate into a date in the datetime format
WITH now,
date(
{year:toInteger(right(date_of_birth,4)),
month:toInteger(substring(date_of_birth,3,2)),
day: toInteger(left(date_of_birth,2))
}) AS date_of_birth
RETURN duration.between(dateOfBirth,now).years AS age

How to get date in UTC time zone using Dataweave

I have the following dataweave expression that displays the time and date that is 90 days before today's date in my local timezone (IST), I want to get the timezone as GMT+00:00 instead of GMT+05:30
my dataweave expression:
%dw 2.0 var time= now() output application/json
---
{
"date" : time - ("P$(90)D" as Period)
}
current output:
{
"date": "2020-11-12T09:14:15.908+05:30"
}
desired output
{
"date": "2020-11-12T09:14:15.908+00:00"
}
there are so many ways to show the timeZone , I let you know one example that I have tried for you
your input was now()
%dw 2.0
var time= now()
output application/json
---
{
"date": (now() >> 'UTC') as DateTime {format: "dd-MMM-yy hh.mm.ss.SSSSSSSSS a VV"} as String {format: "yyyy-MM-dd'T'HH:mm:ss:SSS Z"}
}
the output of this code is:
{
"date": "2021-02-10T07:09:11:815 +0000"
}
Note: There is no time difference between Greenwich Mean Time (GMT) and Coordinated Universal Time (UTC)
This code you can easily modify according to your requirement for example if you want the same code for GMT +5:30 that is Asia/Calcutta time Zone ID
that will be as below
%dw 2.0
var time= now()
output application/json
---
{
"date": (now() >> 'Asia/Calcutta') as DateTime {format: "dd-MMM-yy hh.mm.ss.SSSSSSSSS a VV"} as String {format: "yyyy-MM-dd'T'HH:mm:ss:SSS Z"}
}
so main point is here that you need to specify the time zone ID to get that in your output
and this is the official document link that shows a list of all Time Zone ID's in mulesoft at the present day (10-02-2021)- https://docs.mulesoft.com/mule-runtime/4.3/dataweave-cookbook-change-time-zone
Thanks

In snowflake how to get the date as i wanted format in snowflake

I have been facing the issue while retrieving year from snowflake table.
My table has value as below:
year :20
day:10
month :02
I need to dob value as 2020-10-02. When I am using the concat_ws I'm getting expected result, however the padded with 00 the dob printed like 0020-10-02.
Also when we have 99 in the year column then while retrieving it should display 1999
I have created query as below:
select to_date('concat_ws('-',json:year::varchar,json:month::varchar,json:date::varchar)', 'MM/DD/YYYY') from XXX;
Suggest me if any functions also.
Take a look at this
YY
Two-digit year, controlled by the TWO_DIGIT_CENTURY_START session parameter, e.g. when set to 1980, values of 79 and 80 parsed as 2079 and 1980 respectively.
select TO_DATE('99-10-02','YY-MM-DD');
There's no way to have automagically the "right" year display before, if some of your users are going to be very young and others very old, how could you know for sure if the person was born in 20th or 21st century?
I didn't quite get how your data is stored, so I'll assume a json structure since it appears in your query.
set json = '{
"elements": [{
"year": "01",
"month": "02",
"day": "10"
}, {
"year": "99",
"month": "02",
"day": "10"
}, {
"year": "20",
"month": "02",
"day": "10"
}]
}'::varchar;
Now I'll parse the json, extract the values, putting that here so you can make sure we're having the same data structure.
CREATE OR REPLACE TEMP TABLE test AS
select t2.VALUE: day::varchar dob_day,
t2.VALUE: month::varchar dob_month,
t2.VALUE: year::varchar dob_year
from (select parse_json($json) as json) t,
lateral flatten(input => parse_json(t.json), path => 'elements') t2
Now is the part that will interest you. It is dirty trick and assumes that if the two digit year is higher than the current two digit year, then it cannot be 2000, but instead 1900.
SELECT to_date(concat_ws('-',
IFF(t2.dob_year > RIGHT(extract(year, current_timestamp), 2), '19'||t2.dob_year , '20'||t2.dob_year ),
t2.dob_month,
t2.dob_day)) proper_date
FROM test t2;
Change the date format in your to_date to 'YY-MM-DD' should give you DOB you want, and I suggest to use try_to_date if you suspect data issues as it will NULL the field if not a valid date.
NOTE if you are using US formatting then use YY-DD-MM (the month in the end)
select to_date('concat_ws('-',json:year::varchar,json:month::varchar,json:date::varchar)', 'YY-MM-DD') from XXX;
Also, if you want to safely check that the DOB is not in future then add IFF as follows
IFF(CURRENT_DATE > to_date('concat_ws('-',json:year::varchar,json:month::varchar,json:date::varchar)', 'YY-MM-DD'), to_date('concat_ws('-',json:year::varchar,json:month::varchar,json:date::varchar)', 'YY-MM-DD'),NULL);

device telemetry page is at 1970

I have a data converter that generates the following output
[{
"deviceName": "meter 34936959",
"groupName": "All",
"ts": 1579788289,
"values": {
"counter": 2686
}
}]
timestamp is 1579788289, which is Thursday, 23 January 2020 14:04:49
but in the device page, latest telemetry is "1970-01-19 08:49:48"
can you please help me to understand what is wrong with the structure?
Thank you
It is expecting a timestamp in milliseconds, but you are supplying a timestamp in seconds.
1579788289 seconds since 1970 is "2020-01-23 14:04:49"
1579788289 milliseconds since 1970 is "1970-01-19 08:49:48"
There is an example of this in the ThingsBoard documentation:
In the example above, we assume that “1451649600512” is a unix
timestamp with milliseconds precision.
If you can't get the millisecond timestamp, try multiplying your timestamp by 1000 before sending it. With your example, that would be:
[{
"deviceName": "meter 34936959",
"groupName": "All",
"ts": 1579788289000,
"values": {
"counter": 2686
}
}]

Chartkick linechart displays previous date with different time

In my Ruby on Rails application , i have the below json and i am displaying the linechart from chartkick. In linechart , it shows previous day's date though date is correct in the json. When i use format it displays the date fully. How we can display only the date in x axis. My json from controller
[["2018-05-27T00:00:00.000Z", #<BigDecimal:558070d10920,'0.3206E2',18(18)>],
["2018-05-29T00:00:00.000Z", #<BigDecimal:558070d10060,'0.23848E3',18(18)>],
["2018-05-30T00:00:00.000Z", #<BigDecimal:558070d0b420,'0.33899E3',18(18)>],
["2018-05-31T00:00:00.000Z", #<BigDecimal:558070d0a548,'0.83962E3',18(18)>]]
Please find the code used
<%= line_chart [name: 'Sales Amount ', data: #daily_sales_debit_data],
xtitle: 'Period',
ytitle: 'Sales Amount',
library: {
vAxis: { format: "currency" },
legend: { position: 'in'},"format":"dd/MM/yy"},
"discrete":true%>
In the graph , it is being displayed as below . how can i format the date being displayed in x axis without time .
2018-05-08T00:00:00.000Z
2018-05-09T00:00:00.000Z
2018-05-14T00:00:00.000Z
2018-05-15T00:00:00.000Z
2018-05-16T00:00:00.000Z
2018-05-18T00:00:00.000Z
2018-05-19T00:00:00.000Z
2018-05-21T00:00:00.000Z
2018-05-22T00:00:00.000Z
2018-05-25T00:00:00.000Z
2018-05-27T00:00:00.000Z
2018-05-29T00:00:00.000Z
2018-05-30T00:00:00.000Z
2018-05-31T00:00:00.000Z
Formatting the date in the proper format - "MM-DD-YYYY" worked

Resources