BJ5
BJ5

Reputation: 512

Solr - Facing issue in matching dates

I am facing an issue in solr. I am not able to match dates I am working in solr 5.5

Below is the part of my schema

  <!--Application fields -->
  <fieldType name="long_field" class="solr.TrieLongField"/>
  <fieldType name="timestamp_field" class="solr.TrieDateField"/>
  <fieldType name="string_field" class="solr.StrField"/>
  <fieldType name="text_field" class="solr.TextField"/>

  <field name="tweet_id" type="long_field" indexed="false" stored="false"/>
  <field name="unixtime" type="string_field" indexed="false" stored="false"/>
  <field name="timestamp" type="timestamp_field" indexed="false" stored="true"/>
  <field name="lang" type="string_field" indexed="false" stored="true"/>
  <field name="user" type="text_field" indexed="false" stored="true"/>
  <field name="timezone" type="text_field" indexed="false" stored="true"/>
  <field name="tweet_text" type="text_field" indexed="false" stored="true"/>
  <!--Application fields -->

This is the sample data when I give the query

http://172.28.128.3:8983/solr/tweets_shard1_replica1/select?q=id:75bfb093-033c-41fa-8712-814f17da7c54

<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">7</int>
<lst name="params">
<str name="q">id:75bfb093-033c-41fa-8712-814f17da7c54</str>
</lst>
</lst>
<result name="response" numFound="1" start="0">
<doc>
<date name="timestamp">2014-12-31T21:03:06Z</date>
<str name="lang">und</str>
<str name="timezone">Eastern Time (US & Canada)</str>
<str name="user">startup_owner11</str>
<str name="tweet_text">Wow! $GOOG is going down today #BigData</str>
<str name="id">75bfb093-033c-41fa-8712-814f17da7c54</str>
<long name="_version_">1558697655805149184</long>
</doc>
</result>
</response>

Now when I give the below query. I am getting an error

http://172.28.128.3:8983/solr/tweets_shard1_replica1/select?q=*:*&fq=timestamp:2014-12-31T21:03:06Z

Below is the response from solr

<response>
<lst name="responseHeader">
<int name="status">400</int>
<int name="QTime">1</int>
<lst name="params">
<str name="q">*:*</str>
<str name="fq">timestamp:2014-12-31T21:03:06Z</str>
</lst>
</lst>
<lst name="error">
<lst name="metadata">
<str name="error-class">org.apache.solr.common.SolrException</str>
<str name="root-error-class">org.apache.solr.common.SolrException</str>
</lst>
<str name="msg">Invalid Date String:'2014-12-31T21'</str>
<int name="code">400</int>
</lst>
</response>

Please help

Upvotes: 0

Views: 226

Answers (1)

Vinod
Vinod

Reputation: 1953

Two things you missed

  1. you should escape(:) while querying datefield.

timestamp:2014-12-31T21\:03\:06Z

  1. set index="true" for timestamp field.

<field name="timestamp" type="timestamp_field" indexed="true" stored="true"/>

reindex and run your query

http://172.28.128.3:8983/solr/tweets_shard1_replica1/select?q=*:*&fq=timestamp:2014-12-31T21\:03\:06Z

Hope this Helps, vinod

Upvotes: 1

Related Questions