You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@solr.apache.org by Teresa McMains <te...@t14-consulting.com> on 2022/03/17 20:46:40 UTC

Return formatted dates from solr query

Client has a date field which is stored in database as a date/time.

The field is defined as follows in schema.xml:

<field name="TRANSACTION_DATE" type="tdate" indexed="true" stored="true" multiValued="false" required="false" />

Where tdate is:

  <!-- A Trie based date field for faster date range queries and date faceting. -->
  <fieldType name="tdate" class="solr.TrieDateField" precisionStep="6" positionIncrementGap="0"/>

Query is formatted as follows (this is shortened for ease of reading):

'/solr/aml/select?q=TRANSACTION_REFERENCE_NUMBER%253A%2522${transactionReferenceNumber}%2522&wt=json&fl=_1_Trigger:def(TRIGGER_IND,%2522N%2522),_4_Transaction_Date:TRANSACTION_DATE,_5_Amount:CURRENCY_AMOUNT,%26fq=doc_type%253Atrxn&rows=100000&start=0'

I would like to return the transaction date as a date without the time stamp or time zone but instead it looks like this:
[cid:image001.png@01D83A1E.923275C0]

Do you know how I might have it strip the timestamp and time zone using a function in the query? Or do I have to change schema.xml (and to what)?

Thank you!!
Teresa


Re: Return formatted dates from solr query

Posted by Thomas Corthals <th...@klascement.net>.
If the desired output format is the same for every query, I would store
the formatted date in a separate string field when indexing. You can query
the date field, but return the string field instead.

Thomas

Op do 17 mrt. 2022 om 22:08 schreef Shawn Heisey <el...@elyograg.org>:

> On 3/17/22 14:46, Teresa McMains wrote:
> > I would like to return the transaction date as a date without the time
> > stamp or time zone but instead it looks like this:
> >
> > Do you know how I might have it strip the timestamp and time zone
> > using a function in the query? Or do I have to change schema.xml (and
> > to what)?
>
> I started the techproducts example, which has a field type of pdate,
> using a Point type rather than the Trie type you are using, but I
> believe that the Trie type behaves the same.
>
> We cannot see your image.  The mailing list ate it.  You'll need to give
> us text, not an image.
>
> Here is what I get when I add a document to the example techproducts
> index with a date value and then query for that document:
>
> |"response":{"numFound":1,"start":0,"numFoundExact":true,"docs":[ {
> "id":"foo1", "test_dt":"2009-04-05T12:34:56Z",
> "_version_":1727582227100860416}] There is no timezone. It's always in
> UTC. Any transformation to a timezone or the removal of the timestamp
> would need to be done in your application that queries Solr before
> giving the result to the end user. You might also want to investigate
> the DateRangeField class. It has concepts of values that represent an
> entire time period, such as a whole day. Thanks, Shawn |
>
>

Re: Return formatted dates from solr query

Posted by Shawn Heisey <el...@elyograg.org>.
On 3/17/22 14:46, Teresa McMains wrote:
> I would like to return the transaction date as a date without the time 
> stamp or time zone but instead it looks like this:
>
> Do you know how I might have it strip the timestamp and time zone 
> using a function in the query? Or do I have to change schema.xml (and 
> to what)?

I started the techproducts example, which has a field type of pdate, 
using a Point type rather than the Trie type you are using, but I 
believe that the Trie type behaves the same.

We cannot see your image.  The mailing list ate it.  You'll need to give 
us text, not an image.

Here is what I get when I add a document to the example techproducts 
index with a date value and then query for that document:

|"response":{"numFound":1,"start":0,"numFoundExact":true,"docs":[ { 
"id":"foo1", "test_dt":"2009-04-05T12:34:56Z", 
"_version_":1727582227100860416}] There is no timezone. It's always in 
UTC. Any transformation to a timezone or the removal of the timestamp 
would need to be done in your application that queries Solr before 
giving the result to the end user. You might also want to investigate 
the DateRangeField class. It has concepts of values that represent an 
entire time period, such as a whole day. Thanks, Shawn |