Document in the migration guide that sort by Long @Id doesn't work anymore


I recently upgraded from 5.3.0.Final to 5.6.0.Alpha3, following the migration guide.

As soon as I did I noticed that sorting HS queries by "id" field (id is the name of the property that I have annotated with @Id) simply fails silently. I.e., no exception is thrown, but results are not sorted by id. This property is of type Long, which means that the Lucene field is of type NUMERIC.

I then saw the following warning emitted by Hibernate whenever I run my query:

Ok, I added the @SortableField annotation and reindexed, then tried running the query again. This time I got an exception:

I tried changing the type in my SortField but alas - the SortField.Type enum doesn't contain a value named "SORTED".


Win10x64, JDK 8


Guillaume Smet
April 14, 2016, 12:05 PM

Hi Ido!

Thanks for the very detailed report. I had the same issue with our applications: the fact is that it's considered a bad practice to use the @Id field to sort your results.

You need to define another field with @Field and a @SortableField for this new field. Then you should use this new field to sort your results.

It's probably worth a mention in the migration guide.

Ido Dovrat
April 14, 2016, 12:25 PM

Thanks. I didn't exactly add a new Java field, but I did generate an additional Lucene field based on the id property, simply by doing this:

Then I use the id_forSort field for my SortField instead of the id field.

Guillaume Smet
April 14, 2016, 1:03 PM

That's what I meant so you're good to go!

Guillaume Smet
September 5, 2016, 2:35 PM


Guillaume Smet
September 5, 2016, 2:36 PM

I added a note about this in the Migration guide of the 5.5 release.


Guillaume Smet


Ido Dovrat



Suitable for new contributors


Pull Request


Feedback Requested


Fix versions

Affects versions