Sorting not working when update entity

Hi,
I am using hibernate search 5.11 , i have added base entity below
@CreationTimestamp
@Column(updatable = false, name = “created_date”)
@Field(analyze = Analyze.NO,store = Store.NO)
@SortableField
private LocalDateTime createdDate;

and for sort
sort = queryBuilder
.sort()
.byField(“createdDate”).desc() // Descending order
.createSort();
Sorting is working when I add new item but when I update this item sorting not working.
Note – Other entity extends this base entity.

Hello.

We will need more information.

  • Be more specific about what you mean by “not working”: show some example data with the expected order vs. the actual order.
  • Be more specific about what you do when you “update items”: show the code that performs the actual update, in particular the properties that are modified.
  • Be more specific about the type involved; I understand there are two? Are both those types annotated with @Indexed?

… Also, this is a creation date, not a “last update” date, and the column in question is marked as “not updateable”, so I’m not sure what you mean by “when I update this item”. You probably confused this property with another one?

Hi

  1. Order should be in descending but i got
    {
    “id”:“3”,
    “createdDate”:“2021-06-13 13:24:56”
    } ,
    {
    “id”:“2”,
    “createdDate”:“2021-06-12 13:24:56”
    } ,
    {
    “id”:“5”,
    “createdDate”:“2021-06-14 13:24:56” // this item details updated (createdDate not update)
    }

  2. I update title for particular item (createdDate not update)

3 Yes both type are annotated with @Indexed

I am using base entity and extends this to other entity.
when I update I simply get information from db by id and update the title and then persist it.

Okay, I don’t know why you keep mentioning updates and why you keep not showing the code, but regardless the order seems wrong.

After you create the sort, do you add it to the query with query.setSort(sort);?

If so, and if it still doesn’t work, please enable logging of Elasticsearch requests by setting the log level of category org.hibernate.search.elasticsearch.request to TRACE, then paste the log output when executing your search query here.

Please format this properly with ``` before and after the logs, like this:

```
...my logs...
...some more logs...
```

Please find details

@indexed(name=“Item”)
public class Item extends BaseEntity{

@Id
Long id

@Field
private String title;

}

@indexed(name=“BaseEntity”)
public class BaseEntity{

@CreationTimestamp
@Column(updatable = false, name = “created_date”)
@Field(analyze = Analyze.NO,store = Store.NO)
@SortableField
private LocalDateTime createdDate;
}

public Item updateItem(Long id,String title){

try{
Optional item = itemRepository.findById(id);
if(item.isPresent()) {
item.get().set(title);
itemRepository.save(item.get())
return item;
}
else{
throw new CustomException(“Item with id “+id+” not found”,HttpStatus.NOT_FOUND);
}
}
catch(Exection e){
log.error(“Error::{}”,e.getMessage());
throw new CustomException(“Something went wrong”,HttpStatus.INTERNAL_SERVER_ERROR,e.getMessage());
}

}

I will try to reproduce logs