On Wed, Sep 11, 2013 at 02:58:52PM +0000, Adrian wrote:
Hi,
is it possible to fetch the stored long value of the date field using the
Java API, when this field is included in a SearchHit?
When trying to cast the value explicitly to Long using Elasticsearch 0.90.3, this
fails with a ClassCastException (String cannot be casted to Long), regardless
if SearchFieldHit#getValue() or SearchFieldHit#getValue() is used.
So I tried to iterate over the values using (SearchFieldHit#getValues()), but
only String objects were returned.
Does anyone have a point on how to fetch the orginal Long value? A possible
solution would be to parse the returned String - I like to avoid that if possible.
During indexing how are you defining the value for this date field? A date
formatted string or as a long value?
Dates are formatted into the string format as was provided during indexing.
Also is the date field configured to be stored separately? (stored option
in mapping)
On Wed, Sep 11, 2013 at 02:58:52PM +0000, Adrian wrote:
Hi,
is it possible to fetch the stored long value of the date field using the
Java API, when this field is included in a SearchHit?
When trying to cast the value explicitly to Long using Elasticsearch
0.90.3, this
fails with a ClassCastException (String cannot be casted to Long),
regardless
if SearchFieldHit#getValue() or SearchFieldHit#getValue() is used.
So I tried to iterate over the values using (SearchFieldHit#getValues()),
but
only String objects were returned.
Does anyone have a point on how to fetch the orginal Long value? A possible
solution would be to parse the returned String - I like to avoid that if
possible.
On Thu, Sep 12, 2013 at 12:02:39PM +0200, Martijn v Groningen wrote:
Martijn,
During indexing how are you defining the value for this date field? A date
formatted string or as a long value?
I've got a formatter (using the "format" option) for this, since the documents
contain the timestamp in a formatted fashion.
Dates are formatted into the string format as was provided during indexing.
Even if the type "date" is defined on that field? I assumed that, this
formatter was ony used for parsing the formatted date into the (internal) Long
representation.
Also is the date field configured to be stored separately? (stored option
in mapping)
I've set no specific store option in my mapping, so the defaults should apply.
The date is just returned in the format you have provided it with.
Internally the date is converted into a long, but that is only put into the
inverted index, not the source you're fetching the field from.
Do you only need to represent a date as a long? If that is the case you can
represent the data as long during indexing. Just make sure the field is
configured as a date field in the mapping. You can then just retrieve a
long value with converting it.
On Thu, Sep 12, 2013 at 12:02:39PM +0200, Martijn v Groningen wrote:
Martijn,
During indexing how are you defining the value for this date field? A
date
formatted string or as a long value?
I've got a formatter (using the "format" option) for this, since the
documents
contain the timestamp in a formatted fashion.
Dates are formatted into the string format as was provided during
indexing.
Even if the type "date" is defined on that field? I assumed that, this
formatter was ony used for parsing the formatted date into the (internal)
Long
representation.
Also is the date field configured to be stored separately? (stored option
in mapping)
I've set no specific store option in my mapping, so the defaults should
apply.
On Thu, Sep 12, 2013 at 07:02:44PM +0200, Martijn v Groningen wrote:
Martijn,
Internally the date is converted into a long, but that is only put into the
inverted index, not the source you're fetching the field from.
I assume the internal representation is used for calculating date histogram
facets too?
Do you only need to represent a date as a long? If that is the case you can
represent the data as long during indexing. Just make sure the field is
configured as a date field in the mapping. You can then just retrieve a
long value with converting it.
The reason why I would like to fetch the long value is to provide localized
formatting (US, ISO, etc.) for date fields. Using long as basis is quite simple
then ..
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.