I'm having trouble wrapping my head around the best way to solve this and could use some outside opinions. In my ES data, I have news articles from the past ~100 years. I'm trying to figure out the best way to search for articles by attributes of a date, not a date range. Here are some for-instances:
Get articles "on this day", e.g. April 15, regardless of year.
Search for articles written between specific hours, e.g. 9am-5pm, or days of the week e.g. Saturdays and Sundays.
Search for articles written during June, July, and August (again, regardless of year).
... and so on. The best solution I've come up with is to store these attributes separately in the index, e.g.
{
"publish_date": {
"full": "2014-04-15 12:34:56",
"year": 2014,
"month": 4,
"monthname": "april",
"day": 15,
"dayofweek": "tuesday",
"dayofyear": 105,
"hour": 12,
"minute": 34,
"second": 56,
"week": 16
}
}
I'm not happy with this solution and I want to break up with it.
Any thoughts on what you would do differently, or how you'd solve this problem?
Thanks!
first off, why aren't you happy with it? It's perfectly fine and in-line with the 'denormalization' hat you probably need to start wearing when doing document-modeling in ES (and other denormalized / nosql databases)
Having said that, you don't need to write the different fields in your own indexing-code. Instead you could go for:
using multi-fields, which allows 1 input field to be indexed to multiple ES-fields, each with there own mapping. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#_multi_fields_3
define such a ES-field for each date-mapping you want to do: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-date-format.html
Related
I am using events trigger in ADF v2. My trigger parameter values look like this:-
"parameters": {
"FolderPath": "#triggerBody().folderPath",
"FileName": "#triggerBody().fileName",
"Year": "#{split(#triggerBody().folderPath,'/')[2]}",
"Month": "#{split(#triggerBody().folderPath,'/')[3]}",
"Day": "#{split(#triggerBody().folderPath,'/')[4]}",
}
I initially ran it with just 2 initial parameters and the sample values for FolderPath look like this as seen from ADF monitor after a run is succeeded:-
test/poc/2019/09/20/00
But when I add other parameters to it, like Year, Month, Day as shown here, while publishing the changes, I get an error 'Trigger activation failed':-
When I hard coded Year, Month, Day in the trigger, it again started working. I am guessing some issues in calling expression language functions from event based trigger. I am basically trying to dynamically calculate individual elements from FolderPath such as 2019 as Year, 09 as Month and so on. How to achieve this?
Pasting DraganB's comment as an answer here:-
Try
"Year": "#{split(triggerBody().folderPath,'/')[2]}", "Month": "#{split(triggerBody().folderPath,'/')[3]}", "Day": "#{split(triggerBody().folderPath,'/')[4]}"
Basically delete # before triggerBody
I am currently trying to setup my own holiday iCalendar to which I can subscribe on, since I don't want to depend on 3rd party services.
I am currently trying to make the the VEVENTs for Christmas. The 2nd, 3rd and 4th advent, as well as the Christmas holidays are straight forward, however I have big issues to model the 1st advent.
Specifically, the problem is that the first advent can be in November and December (27th November to 3rd Devember)
How can I make a recurring event (or, more specifically, the RRULE) to cover all cases for the 1st advent?
What I've tried
My first idea was this:
FREQ=YEARLY;INTERVAL=1;BYMONTH=11,12;BYMONTHDAY=27,28,29,30,1,2,3;BYDAY=SU
The idea was to just pick the one Sunday in between 27th November and 3rd December. This does of course not work because BYMONTH expands the search to all days in November and December, and BYMONTHDAY limits the search to those days in both months. I.e. November 1st, November 2nd, ... December 27th, December 28th, ..., which is of course not what I want.
Next, I tried to use BYYEARDAY=331,332,333,334,335,336,337 instead of BYMONTHDAY and BYMONTH, but unfortunately my webdav server (Nextcloud, which uses Sabre as far as I know. I got an error message "Invalid BYYEARDAY rule") does not support this.
My next idea was to use multiple RRULEs -- at least I did not see any passage in the RFC stating that only one RRULE is allowed at most. So I ended up with:
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=SU;BYMONTHDAY=27,28,29,30;BYMONTH=11
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=SU;BYMONTHDAY=1,2,3;BYMONTH=12
Didn't work as well. My last resort was to create two separate VEVENTs, one with the first RRULE above and one with the second RRULE above, but otherwise identical. This worked, but it left me confused.
Is there no better solution? How would you do it?
unfortunately my webdav server (Nextcloud, which uses Sabre as far as I know. I got an error message "Invalid BYYEARDAY rule") does not support this.
Well I think you should raise a bug report, because as far I can tell your solutions are correct and RFC-compliant.
I tried your solutions 2 and 3 with different libs (my own lib php-rrule, and rrule.js) and both options seems to work just fine.
FREQ=YEARLY;BYDAY=SU;BYYEARDAY=331,332,333,334,335,336,337
or combining 2
FREQ=YEARLY;INTERVAL=1;BYDAY=SU;BYMONTHDAY=27,28,29,30;BYMONTH=11
FREQ=YEARLY;INTERVAL=1;BYDAY=SU;BYMONTHDAY=1,2,3;BYMONTH=12
will both produce:
2018-12-02
2019-12-01
2020-11-29
2021-11-28
2022-11-27
2023-12-03
2024-12-01
2025-11-30
2026-11-29
2027-11-28
which according to Google and Wikipedia are the correct dates for the 1st Advent Sunday in the next 10 years.
Side note
at least I did not see any passage in the RFC stating that only one RRULE is allowed at most.
While not strictly forbidden, in RFC 5545 it's literally written everytime RRULE is mentioned:
;
; The following is OPTIONAL,
; but SHOULD NOT occur more than once.
;
rrule
Appendix A even states in the "New restrictions":
2. The "RRULE" property SHOULD NOT occur more than once in a
component.
That being said, multiple RRULE is a great feature, I don't know why they restricted it.
If I'm not mistaken, the first Advent is always the fifth last Sunday in a year. So the following rule should do the trick:
FREQ=YEARLY;BYDAY=-5SU
See the next 10 results: http://recurrence-expansion-service.appspot.com/reaas?dtstart=20181202&rrule=FREQ%3DYEARLY%3BBYDAY%3D-5SU&max_instances=10
Or to put it another way:
FREQ=YEARLY;BYDAY=SU;BYSETPOS=-5
I have the following time format:
Dec 29, 2016 10:57:58 PM
How can I display it in a model of days ago. Like 10days or 20days using Freemarker?
Thank you.
FreeMarker templates don't do calendar calculations, or at least not unless you add a TemplateMethodModelEx for them. But in principle such data should come from the data-model, rather than calculated by the template.
Though, depending on how you define "days ago", something like ((.now?long - someDate?long) / 86400000)?ceiling might works, assuming someDate is a real date-time value and not just a string. But it's ugly.
we have enabled the October 2nd 2013 breaking changes for our application yesterday, the change to the application settings is already confirmed. If I submit bid_info in the new format (with strings instead of numeric indexes) it works:
"bid_info": {
"CLICKS": 75
}
When I try to read the ad group with a request to its url later, I get a bid_info and a max_bid setting in parallel (I expected that max_bid will be removed in October 2nd-mode), but the bid_info contains the numeric index and not the expected CLICKS-string:
(...)
"adgroup_status": 3,
"bid_type": 1,
"max_bid": 75,
"bid_info": {
"1": 75
},
"ad_status": 3,
"locations": [
3
],
(...)
Any suggestions for that? Is this bug or by design? Or did something went wrong with the activation of the October 2nd changes for our application?
Bye
Tobias
Same for me but without activating october 2nd breaking changes...
It's quite strange to have number as name field and it is not allowed in languages like in c#.
It should be this kind of info:
A dictionary of values that you place on your bid
CPM={'REACH':cent_value}
CPC={'CLICKS':cent_value}
oCPM or CPA={'ACTIONS':cent_value}
I've 1, 38, 44, 55 in place of this.
Update, it's actually this:
Actions: 55
Reach: 44
Clicks: 1
Social Impressions: 38
More info: https://developers.facebook.com/docs/reference/ads-api/optimizedcpm/
https://developers.facebook.com/bugs/539767489417940?browse=external_tasks_search_results_5203fffd63da04c48847913
I actually filed a ticket against this. The Facebook bug response said it would be fixed on July 17th, however a contact at Facebook elevated this ticket after it was not fixed on July 17th, and it is now being currently worked on.
We were told it should be functional by the end of August.
Currently if my post has date: 2013-06-16 in my post, and I do #document.date in the post layout I get "Sat Jun 15 2013 19:00:00 GMT-0500 (CDT)".
I would like to get different formats. Like 2013-06-16 for the pubdate HTML5 tag (or something similar).
Or Jun 15, 2013 for the human readable post date, etc.
How can I accomplish this? BTW my layouts are using the .html.coffee file extension. :)
Figured it out! This is my docpad.coffee file:
https://github.com/Greduan/eduantech.docpad/blob/bcc91a247e9741f4ce8aa5883634fac26c9859a5/docpad.coffee#L4-L5
https://github.com/Greduan/eduantech.docpad/blob/bcc91a247e9741f4ce8aa5883634fac26c9859a5/docpad.coffee#L41-L43
And here's my post template:
https://github.com/Greduan/eduantech.docpad/blob/bcc91a247e9741f4ce8aa5883634fac26c9859a5/src/layouts/post.html.coffee#L7-L8
Of course I only linked the relevant parts of the code. Basically I learned and used Moment.js. :)
Although I love Moment.js, if you prefer a solution that does not require an additional plugin and you don't need to do too much with the date, you could use native JavaScript.
For example, if you would like to output your date in this great, human-readable format: Saturday, November 15, 2014, you can use the following native JavaScript method, passing in an optional locale:
date.toLocaleDateString()
And when you need just the year, e.g. 2014, you can use:
date.getFullYear()
Bear in mind, you will need getFullYear and not getYear due to the whole Y2K thing.
With all of the other native JavaScript date methods, you can make your own combinations, though if you're including multiple date formats, you may want to let Moment.js do the heavy lifting.