To me, the obvious way of doing this would be to CAST the DATETIME to
CHAR(n), or (probably better) use DATE_FORMAT().


On Tue, Dec 17, 2013 at 5:21 AM, Shalin Shekhar Mangar <
shalinman...@gmail.com> wrote:

> I'm sorry. I thought you wanted to parse a date stored as string into
> a java.util.Date. Clearly, you are trying to go the other way round.
>
> There's nothing in DIH which will convert a mysql date to a string in
> specific format. You will need to write a custom transformer either in
> javascript or in java to do this.
>
> http://wiki.apache.org/solr/DIHCustomTransformer
> http://wiki.apache.org/solr/DataImportHandler#ScriptTransformer
>
> On Mon, Dec 16, 2013 at 1:34 PM, manju16832003 <manju16832...@gmail.com>
> wrote:
> > OK here are the scenarios I tried.
> >
> > *Scenario - 1: *
> >
> > dih.xml (aka data-config.xml)
> >
> > <entity dataSource="solr" name="listing" query="..."
> > transformer="DateFormatTransformer">
> >
> > <field name=&quot;publish_date&quot; column=&quot;publish_date&quot;
> > xpath=&quot;/RDF/item/date&quot;
> > dateTimeFormat=&quot;&lt;b>yyyy-MM-dd'T'HH:mm:ss*" locale="en"/>
> >
> > schema.xml
> > <field name="publish_date" type="date" indexed="true" stored="true"
> > multiValued="false" default="NOW" />
> >
> > It does not work. Throws an following exception
> > WARN  org.apache.solr.handler.dataimport.DateFormatTransformer  – Could
> not
> > parse a Date field
> > java.text.ParseException: Unparseable date: "2013-12-05 15:40:03.0"
> >
> > *Scenario - 2*
> > dih.xml (aka data-config.xml)
> >
> > <entity dataSource="solr" name="listing" query="..."
> > transformer="DateFormatTransformer">
> >
> > <field name=&quot;publish_date&quot; column=&quot;publish_date&quot;
> > xpath=&quot;/RDF/item/date&quot; dateTimeFormat=&quot;&lt;b>yyyy-MM-dd
> > HH:mm:ss*" locale="en"/>
> >
> > schema.xml
> > <field name="publish_date" type="date" indexed="true" stored="true"
> > multiValued="false" default="NOW" />
> >
> > Output is
> > <date name="publish_date">2012-12-05T07:38:27Z</date>
> >
> > *Scenario - 3*
> > dih.xml (aka data-config.xml)
> >
> > <entity dataSource="solr" name="listing" query="..."
> > transformer="DateFormatTransformer">
> >
> > <field name=&quot;publish_date&quot; column=&quot;publish_date&quot;
> > xpath=&quot;/RDF/item/date&quot; dateTimeFormat=&quot;&lt;b>yyyy-MM-dd
> > HH:mm:ss*" locale="en"/>
> >
> > schema.xml
> > <field name="publish_date" type="string" indexed="true" stored="true"
> > multiValued="false" default="NOW" />
> >
> > Output is
> >   <str name="publish_date">Thu Dec 05 15:38:27 MYT 2013</str>
> >
> > My expectation was *2012-12-05 07:38:27* (MySQL DateTime format)
> >
> >
> >
> > --
> > View this message in context:
> http://lucene.472066.n3.nabble.com/Storing-MYSQL-DATETIME-field-in-solr-as-String-tp4106836p4106854.html
> > Sent from the Solr - User mailing list archive at Nabble.com.
>
>
>
> --
> Regards,
> Shalin Shekhar Mangar.
>

Reply via email to