Searching elasticsearch from R using URI string with #timestamp range - r

I am trying to modify working URI search from R to retrieve data from ElasticSearch using time range on #timestamp es variable:
here is the uri string:
myuri01 <- paste0( 'myserver01:9201/filebeat-*/_search?pretty=true&size=9000&sort:#timestamp&q=%2BSESTYPE:APPTYPE001%20 2Bhost:mytesthost%20%2B#timestamp>"2016-10-25T18:59:23.250Z"')
retset = getURL(myuri01 )
but I get no data, no errors ... Also tried without double quote around time stamp - same result. If I remove the last timestamp part then I do get the data as expected.
Any help would be appreciated.
Thanks

Related

Bigquery String to date invalid, safe.parse returns null #standardSQL

I am trying to convert a date value ingested from SFMC as a string. Attempts and results below:
PARSE_DATE('%m/%d/%Y', '6/22/2017’) returns “invalid date”
2.safe.PARSE_DATE('%m-%d-%Y',Timesent) returns null results
Any insight would be greatly appreciated.
I wondered if it was because the day of month had no leading zero, because according to the docs, %d means the day of the month as a decimal number (01-31).
But your first example worked OK for me in a BigQuery SQL workspace anyway as per below. Your second example has hyphens rather than slashes in the format mask, and BigQuery returns a mismatch error for me.
Are you certain about the date value which is failing for you?

FTL Date Formatting In Netsuite

I have a date coming through as 25/4/2022. I need it changed to 25/APRIL/2022. I have tried every combination of ?date('dd/mm/yyyy') / ?datetime('dd/mmm/yyyy') ?datetime(dd/mm/yyyy)?string('dd/mmm/yyyy') that I can think of but I keep getting teh same type of errors:
The string doesn't match the expected date/time/date-time format.
The nested reason given follows: Unparseable date: "" ---- FTL stack trace ("~" means nesting-related)
What am I missing here?
You need to use a Java SimpleDateFormat pattern to format dates. If you want the month, use M (uppercase), as m (lowercase) is minutes in hour. For a full month, use MMMM. So, use:
${"25/April/2022"?date("dd/MMMM/yyyy")}
See also:
https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_string_date
https://freemarker.apache.org/docs/ref_directive_setting.html#topic.dateTimeFormatSettings
How to parse month full form string using DateFormat in Java?

SPARQL: Date conversion

In the R package SPARQL, xsd:date datatypes are by default converted into Unix time. This is a problem because this involves two date transformations - the first taking place within the function SPARQL() - which are determined by the local system time zone. This is a problem if you say, let's say in Sydney, Australia (Sys.timezone() == "Australia/Sydney") because the following query, requesting the date of the 2016 US presidential election
query <- "SELECT ?date WHERE {wd:Q699872 wdt:P585 ?date}"
res <- SPARQL('https://query.wikidata.org/sparql', query)
as.POSIXct(res$results$date, origin = '1970-01-01')
will return "2016-11-07" instead of "2016-11-08" (the correct date), which is instead returned if
Sys.setenv(TZ='GMT')
res <- SPARQL('https://query.wikidata.org/sparql', query)
as.Date(as.POSIXct(res$results$date, origin = '1970-01-01'))
Is there any way to ask SPARQL to return date datatypes as characters?
I'm not sure how the R SPARQL package determines it's a date, but assuming it looks at the assigned datatype, you can coerce to string by retrieving only the lexical value:
SELECT (STR(?date) as ?dateString) ....
Of course this only works if the Unix time conversion happens on the result processing side, not during query evalation. If the latter is the case: get a better SPARQL engine.

moment.js and deprecated warning. timestamp to moment date object

I've read thru various posts on here in regards to similiar issues but none have solved my problem.
I manipulate the moment.js date object, and then store it as timestamp.
BUT, when I try to read in that timestamp again, I get that deprecated warning.
""Deprecation warning: moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to https://github.com/moment/moment/issues/1407 for more info."
I've tried toDate(), format(), moment(myTimeStamp, 'ddd, DD MMM YYYY HH:mm:ss ZZ'); --> all generate the warning...
So, for example, my timestamp will look like this:
const timestamp = '1458586740000'
when I read that back and try to parse out the month/day/year, then the hour/min am/pm, etc... I need to get that timestamp into a moment.js object. Nothing is working for me. Any ideas.
How can I get this timestamp: '1458586740000', into a moment.js object so I can extract date date from it as I need?
EDIT: this is how I am storing the timestamp. So I would need to retrieve it from this.
let timeStamp = Moment(state[_Date])
.add({ hour: state[AMPM] === 'PM'
? +state[Hour] + 12
: state[Hour] ,
minute: state[Min] }).format('x')
The X token indicates a unix timestamp in seconds, and the x token indicates a unix millisecond timestamp (offset).
You appear to have a millisecond timestamp, so you would make a moment out of it by doing the following:
var a = moment('1458586740000', 'x')
It works without ' as well:
var a = moment(1458586740000, 'x')
You can also not specify the x and it should work:
moment(1458586740000)
Because you have a unix offset (milliseconds), not a unix timestamp (seconds), moment.unix is not what you want.
Then you can do the following:
a.format()
"2016-03-21T13:59:00-05:00"
Or you can use any of the other formatting tokens listed here to output whatever result you would like: http://momentjs.com/docs/#/displaying/format/
Based on the code you presented, I think you may be having problems because your timestamp is stored as a string (in ''). Parsing as a string causes an invalid date error, because it attempts to match ISO 8601 format and fails. Specifying that 'x' token will cause it to assume unix offset and work correctly.

Using UTCTime with SQLite in Yesod

While using a UTCTime field in my model in Yesod, I get the following error:
PersistMarshalError "field timestamp: Expected UTCTime, received PersistText \"09:18:07\""
I am using SQLite to store my database. My model looks as follows:
Myobject
timestamp UTCTime default=CURRENT_TIME
otherfield Text
Note that this error occurs both with and without the default value.
I am selecting the list of Myobject-entities as follows:
myobjects <- selectList [] [Desc MyobjectTimestamp]
Using MyobjectOtherfield instead of MyobjectTimestamp does not help either, which makes sense since all data is fetched and therefore marshaled anyway.
A similar question has been asked here, but the answer did not help me.
How can I use UTCTime in Yesod while using SQLite?
Edit:
The PersistText \"09:18:07\" that is mentioned in the error is the value the field defaulted to.
You stored a Text value "09:18:07", while it expected a UTCTime value. Did you insert values by hand?
getCurrentTime from Data.Time returns a value of type IO UTCTime, so you can either use putStr getCurrentTime in GHCI to get a valid representation, or use now <- liftIO getCurrentTime in your function.
EDIT:
Because getCurrentTime returns a timestamp like: 2013-10-25 10:16:32.1627238 UTC, inserting a value like that in your database should resolve the error.

Resources