You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Sheetal Deshpande <to...@gmail.com> on 2016/07/12 14:38:26 UTC

Unable to sort using datetime field in Lucene

Hello Java Lucene dev's,

I'm pretty much a newbie when it comes to Lucene. Actually I have a query.
I am using Lucene for indexing logs, so as to make the searching of logs
effective. No doubt, it is working hassle free, but here is something where
I am stuck since days. I want to sort these logs date wise, the latest
being the first in the result(descending order). For this, I have added a
datetime field during indexing in the document.
Something like this:
long dateTime =
DateUtil.getTime(logObject.getDate(),logObject.getTime(),"dd.MM.yyyy
HH:mm:ss:S");
document.add(new LongField("datetime",dateTime,Field.Store.YES));
---
Now while searching, I am adding these lines:
TopDocs result = null;
----code here----
Sort sort = new Sort(new SortField("datetime", SortField.Type.LONG));
result = searcher.search(query,recCountToFetch,sort);
I wished it would work fine, but then I a came across this error:
javax.xml.ws.soap.SOAPFaultException: java.lang.Exception:
java.lang.IllegalStateException: unexpected docvalues type NONE for field
'datetime' (expected=NUMERIC). Use UninvertingReader or index with
docvalues.

Any hint/ suggestions/ guidance on how to tackle this error? Also please
correct me if I am going the wrong way.
Thanks in advance! Anticipating your reply.

-- 
Regards,
Sheetal Deshpande.