You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by mechravi25 <me...@yahoo.co.in> on 2011/09/21 12:38:24 UTC
Solr Indexing - Null Values in date field
Hi,
I have a field in my source with data type as string and that field has NULL
values. I am trying to index this field in solr as a date data type with
multivalued = true. Following is the entry for that field in my schema.xml
<field name="startdate" type="date" indexed="true" stored="true"
multiValued="true" required="false" />
When I try to index, I get the following exception
org.apache.solr.common.SolrException: Invalid Date String:''
at org.apache.solr.schema.DateField.parseMath(DateField.java:163)
at org.apache.solr.schema.TrieDateField.createField(TrieDateField.java:171)
at org.apache.solr.schema.SchemaField.createField(SchemaField.java:95)
at
org.apache.solr.update.DocumentBuilder.addField(DocumentBuilder.java:204)
at
org.apache.solr.update.DocumentBuilder.toDocument(DocumentBuilder.java:277)
at
org.apache.solr.update.processor.RunUpdateProcessor.processAdd(RunUpdateProcessorFactory.java:60)
at org.apache.solr.handler.dataimport.SolrWriter.upload(SolrWriter.java:75)
at
org.apache.solr.handler.dataimport.DataImportHandler$1.upload(DataImportHandler.java:292)
at
org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:618)
at
org.apache.solr.handler.dataimport.DocBuilder.doFullDump(DocBuilder.java:261)
at
org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:185)
at
org.apache.solr.handler.dataimport.DataImporter.doFullImport(DataImporter.java:333)
at
org.apache.solr.handler.dataimport.DataImporter.runCmd(DataImporter.java:391)
at
org.apache.solr.handler.dataimport.DataImporter$1.run(DataImporter.java:372)
I even tried giving the IFNULL condition in my query for that field(Eg:
IFNULL(startdate,'') and also IFNULL(startdate,NULL)) but still I am getting
the same exception.
Is there any way to index the null values as such in date field?
Please help.
--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-Indexing-Null-Values-in-date-field-tp3355068p3355068.html
Sent from the Solr - User mailing list archive at Nabble.com.
Re: Solr Indexing - Null Values in date field
Posted by Erick Erickson <er...@gmail.com>.
Solr dates are very specific, and your parsing exception is expected. See:
http://lucene.apache.org/solr/api/org/apache/solr/schema/DateField.html
Best
Erick
On Thu, Sep 22, 2011 at 6:28 AM, mechravi25 <me...@yahoo.co.in> wrote:
> Hi,
>
> Thanks for the suggestions. This is the option I tried.
>
> I changed the data type in my source to date and then indexed the field once
> again.
>
> for the particular field , in my query in dataimport file, I gave the
> following condition IFNULL(startdate,NULL).
>
> The document was indexed sucessfully. But the field startdate was not
> present in the document.
>
> I have few other records in my source where in there is a value present in
> the startdate but when I index that I am getting this exception
>
> org.apache.solr.common.SolrException: Invalid Date String:'2011-09-21
> 18:28:32.733'
> at org.apache.solr.schema.DateField.parseMath(DateField.java:163)
> at org.apache.solr.schema.TrieDateField.createField(TrieDateField.java:171)
> at org.apache.solr.schema.SchemaField.createField(SchemaField.java:95)
> at
> org.apache.solr.update.DocumentBuilder.addField(DocumentBuilder.java:204)
> at
> org.apache.solr.update.DocumentBuilder.toDocument(DocumentBuilder.java:277)
> at
> org.apache.solr.update.processor.RunUpdateProcessor.processAdd(RunUpdateProcessorFactory.java:60)
> at org.apache.solr.handler.dataimport.SolrWriter.upload(SolrWriter.java:75)
> at
> org.apache.solr.handler.dataimport.DataImportHandler$1.upload(DataImportHandler.java:292)
> at
> org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:618)
> at
> org.apache.solr.handler.dataimport.DocBuilder.doFullDump(DocBuilder.java:261)
> at
> org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:185)
> at
> org.apache.solr.handler.dataimport.DataImporter.doFullImport(DataImporter.java:333)
> at
> org.apache.solr.handler.dataimport.DataImporter.runCmd(DataImporter.java:391)
> at
> org.apache.solr.handler.dataimport.DataImporter$1.run(DataImporter.java:372)
>
>
> Please help.
>
>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Solr-Indexing-Null-Values-in-date-field-tp3355068p3358752.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
Re: Solr Indexing - Null Values in date field
Posted by mechravi25 <me...@yahoo.co.in>.
Hi,
Thanks for the suggestions. This is the option I tried.
I changed the data type in my source to date and then indexed the field once
again.
for the particular field , in my query in dataimport file, I gave the
following condition IFNULL(startdate,NULL).
The document was indexed sucessfully. But the field startdate was not
present in the document.
I have few other records in my source where in there is a value present in
the startdate but when I index that I am getting this exception
org.apache.solr.common.SolrException: Invalid Date String:'2011-09-21
18:28:32.733'
at org.apache.solr.schema.DateField.parseMath(DateField.java:163)
at org.apache.solr.schema.TrieDateField.createField(TrieDateField.java:171)
at org.apache.solr.schema.SchemaField.createField(SchemaField.java:95)
at
org.apache.solr.update.DocumentBuilder.addField(DocumentBuilder.java:204)
at
org.apache.solr.update.DocumentBuilder.toDocument(DocumentBuilder.java:277)
at
org.apache.solr.update.processor.RunUpdateProcessor.processAdd(RunUpdateProcessorFactory.java:60)
at org.apache.solr.handler.dataimport.SolrWriter.upload(SolrWriter.java:75)
at
org.apache.solr.handler.dataimport.DataImportHandler$1.upload(DataImportHandler.java:292)
at
org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:618)
at
org.apache.solr.handler.dataimport.DocBuilder.doFullDump(DocBuilder.java:261)
at
org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:185)
at
org.apache.solr.handler.dataimport.DataImporter.doFullImport(DataImporter.java:333)
at
org.apache.solr.handler.dataimport.DataImporter.runCmd(DataImporter.java:391)
at
org.apache.solr.handler.dataimport.DataImporter$1.run(DataImporter.java:372)
Please help.
--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-Indexing-Null-Values-in-date-field-tp3355068p3358752.html
Sent from the Solr - User mailing list archive at Nabble.com.
Re: Solr Indexing - Null Values in date field
Posted by Pulkit Singhal <pu...@gmail.com>.
Also you may use the script transformer to explicitly remove the field
from the document if the field is null. I do this for all my sdouble
and sdate fields ... its a bit manual and I would like to see Solr
enhanced to simply skip stuff like this by having a flag for its DIH
code but until then it suffices:
... transformer="DateFormatTransformer,script:skipEmptyFields"
<script>
<![CDATA[
function skipEmptyFields(row) {
var regularPrice = row.get( 'regularPrice' );
if ( regularPrice == null || regularPrice == '' ) {
row.remove( 'regularPrice' );
}
var salePrice = row.get( 'salePrice' );
if ( salePrice == null || salePrice == '' ) {
row.remove( 'salePrice' );
}
return row;
}
]]>
</script>
On Wed, Sep 21, 2011 at 6:06 AM, Gora Mohanty <go...@mimirtech.com> wrote:
> On Wed, Sep 21, 2011 at 4:08 PM, mechravi25 <me...@yahoo.co.in> wrote:
>> Hi,
>>
>> I have a field in my source with data type as string and that field has NULL
>> values. I am trying to index this field in solr as a date data type with
>> multivalued = true. Following is the entry for that field in my schema.xml
> [...]
>
> One cannot have NULL values as input for Solr date fields. The
> multivalued part is irrelevant here.
>
> As it seems like you are getting the input data from a database,
> you will need to supply some invalid date for NULL date values.
> E.g., with mysql, we have:
> COALESCE( CreationDate, STR_TO_DATE( '1970,1,1', '%Y,%m,%d' ) )
> The required syntax will be different for other databases.
>
> Regards,
> Gora
>
Re: Solr Indexing - Null Values in date field
Posted by Gora Mohanty <go...@mimirtech.com>.
On Wed, Sep 21, 2011 at 4:08 PM, mechravi25 <me...@yahoo.co.in> wrote:
> Hi,
>
> I have a field in my source with data type as string and that field has NULL
> values. I am trying to index this field in solr as a date data type with
> multivalued = true. Following is the entry for that field in my schema.xml
[...]
One cannot have NULL values as input for Solr date fields. The
multivalued part is irrelevant here.
As it seems like you are getting the input data from a database,
you will need to supply some invalid date for NULL date values.
E.g., with mysql, we have:
COALESCE( CreationDate, STR_TO_DATE( '1970,1,1', '%Y,%m,%d' ) )
The required syntax will be different for other databases.
Regards,
Gora