How to start a Solr Facet date range at the min value of a field? - solr

I'm running a Solr json facet query to get a range of dates for a field (updated_at).
{"updated_at":{
"type":"range",
"field":"updated_at",
"start":"1970-01-01T00:00:00Z",
"end":"NOW",
"gap":"%2B1YEAR",
"missing":false,
"limit":-1}
}'
This works, and shows me yearly ranges starting at 1970, but my earliest date right now is 2019.
How could I dynamically set the start property to the min(updated_at)?
I've tried "start":"min(updated_at)" but that gives me an error:
"error":{
"metadata":[
"error-class","org.apache.solr.common.SolrException",
"root-error-class","org.apache.solr.common.SolrException"],
"msg":"Can't parse value min(updated_at) for field: updated_at",
"code":400}

Related

Craftercms: crafter-search sends multi-value date for repeat group with a single value date field

If you index a repeat group with date fields (xyz_dt), crafter-search will group those dates into a range then sent to Solr. Solr complains xyz_dt is a single value field not multi-value:
Apr 21, 2017 7:21:03 AM org.apache.solr.common.SolrException log
SEVERE: org.apache.solr.common.SolrException: ERROR: [doc=livepublish:/site/components/roadmap/social-responsibility.xml] multiple values encountered for non multiValued field items.item.expiration_dt: [2015-11-19T05:00:00.000Z, 2015-11-24T05:00:00.000Z]
Has this bug been fixed and since what version?

How to count datetime type field on Solr search result?

I want use Solr search and count a result in datetime type field,
If I just use fact_field it will just get 100 rows.
Does anyone have any idea to fix this requirement?
The field like this "created":"2015-09-02T05:57:23Z"
Can I counting this by year or month in Solr?
You can do this with facet.range
If you want to count document by month of current year and previous year :
Use The Below Param :
"facet.range":"created",
"q":"*:*",
"facet.range.gap":"+1MONTH",
"facet":"true",
"facet.range.start":"NOW/YEAR-1YEAR",
"facet.range.end":"NOW"
Example :
http://127.0.0.1:8983/solr/test/select?q=*%3A*&facet=true&facet.range=created&facet.range.start=NOW/YEAR-1YEAR&facet.range.end=NOW&facet.range.gap=%2B1MONTH
Here
facet.range
The facet.range parameter defines the field for which Solr should create range facets. for your case it's created field.
facet.range.start
The facet.range.start parameter specifies the lower bound of the ranges
facet.range.end
The facet.range.end specifies the upper bound of the ranges
facet.range.gap
The span of each range expressed as a value to be added to the lower bound. For date fields, this should be expressed using the DateMathParser syntax (such as, facet.range.gap=%2B1DAY ... '+1DAY'). for your case it's year or month.
Source :
https://cwiki.apache.org/confluence/display/solr/Faceting#Faceting-DateFacetingParameters
https://cwiki.apache.org/confluence/display/solr/Working+with+Dates

Solr: Invalid Date String:'1996'

I am new to Solr. I have indexed some data in my solr(5.1.1). My data has fields like contract_year whose value are like:
contract year: 1996
contract year: 2000
The field type of contract year is "int". I want to change the field type to "date" or "tdate" with just year . For that, I have edited my schema.xml and changed the field type of contract year from "int" to "date". After doing this and reindexing my data, I got this error:
Invalid Date String:'1996'
What should I do to change the field type to "date" and get the same result like
contract year: 1996
without changing the format of date. I want to get only the year(yyyy) from the date.
Thanks for your help
Nupur, the only format that Solr date field support is of the format like this yyyy-MM-dd'T'HH:mm:ss'Z'.So you will have to convert your date in a format like this to be accepted by Apache Solr .

How to boost a document score in Solr based on a Date field and DIstance field without specifying a distance range?

I am constructing a query that searches on the tile. I would like to boost the doc score based on the distance and a date field. Can this be achieved without restricting the distance and date field to a range?
What would the query be if the query field is title and sfield is latlon?
boost to 'wildcarded' distance and date fields, i.e: [* TO *] ?

Solr: org.apache.solr.common.SolrException: Invalid Date String:

I am new to solr and this is my first attempt at indexing solr data, I am getting the following exception while indexing,
org.apache.solr.common.SolrException: Invalid Date String:'2011-01-07'
at org.apache.solr.schema.DateField.parseMath(DateField.java:165)
at org.apache.solr.schema.TrieDateField.createField(TrieDateField.java:169)
at org.apache.solr.schema.SchemaField.createField(SchemaField.java:98)
at org.apache.solr.update.DocumentBuilder.addField(DocumentBuilder.java:204)
at org.apache.solr.update.DocumentBuilder.toDocument(DocumentBuilder.java:277)
I understand from reading some articles that Solr stores time only in UTC, this is the query i am trying to index,
Select id,text,'language',links,tweetType,source,location, bio,url,utcOffset,timeZone,frenCnt,createdAt,createdOnGMT,createdOnServerTime,follCnt,favCnt,totStatusCnt,usrCrtDate,humanSentiment,replied,replyMsg,classified,locationDetail, geonameid,country,continent,placeLongitude,placeLatitude,listedCnt,hashtag,mentions,senderInfScr, createdOnGMTDate,DATE_FORMAT(CONVERT_TZ(createdOnGMTDate,'+00:00','+05:30'),'%Y-%m-%d') as IST,DATE_FORMAT(CONVERT_TZ(createdOnGMTDate,'+00:00','+01:00'),'%Y-%m-%d') as ECT,DATE_FORMAT(CONVERT_TZ(createdOnGMTDate,'+00:00','+02:00'),'%Y-%m-%d') as EET,DATE_FORMAT(CONVERT_TZ(createdOnGMTDate,'+00:00','+03:30'),'%Y-%m-%d') as MET,sign(classified) as sentiment from
Why i am doing this timezone conversion is because i need to group results by the user timezone. How can i achieve this?
Regards,
Rohit
Solr dates must be in the form 1995-12-31T23:59:59Z. You're only giving the date part, but not the time.
See the DateField javadocs for more details.
Date faceting is entirely driven by query params, so if we index your events using the "true" time that they happend at (formatted as a string in UTC) you can then select your date ranges using whatever timezone offset is specified by your user at query time as a UTC offset.
facet.range = dateField
facet.range.start = 2011-01-01T00:00:00Z+${useroffset}MINUTES
facet.range.gap = +1DAY
This would return result in the users timezone and there is actually no need to timezone conversion the query and indexing that column separately.
Regards,
Rohit
Credit For Answer: Chris Hostetter (Solr User Group )

Resources