[hibernate-dev] [Search] Something fishy with sort by id

Hardy Ferentschik hardy at hibernate.org
Thu Sep 24 04:23:18 EDT 2015


Hi,

On Thu, Sep 24, 2015 at 09:23:20AM +0200, Gunnar Morling wrote:
> Either way, you should mark the field to sort on with @SortableField
> which will cause that field to get indexed as doc value field, making
> sorting much faster (see [1] and [2] for the details):
> 
>     @Id
>     @NumericField
>     @SortableField
>     private Long id;

To expand on this - you should not make any assumptions on the id field
or use it for indexing etc. We talked for a long time that we want to prevent
users to use the internal Search document id in queries and for sorting.
This would allow for optimizations of how for example the id is stored and
encoded.

If you need the id value for searches and/or sorting you should use additional
@Field annotations (using @Fields if you need more than one field). So in your 
case you would for example add @Field(name="id_sort", ...). This is the most
future proof solution. 

I don't think that just adding @NumericField will do, since it is just a companion
annotation to @Field.

--Hardy

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 496 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/hibernate-dev/attachments/20150924/f373b73d/attachment.bin 


More information about the hibernate-dev mailing list