question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Supply a custom `Sort.Order` providing Elasticsearch specific parameters

See original GitHub issue

Spring Data Elasticsearch should supply a Sort.Order derived class that can provide custom parameters like ignore_unmapped (see #1908) for an example where this is needed

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:17

github_iconTop GitHub Comments

2reactions
sothawocommented, Mar 20, 2022

it would be nice for Spring Data ES to translate something down into this ES code: SortOrder sortOrder = SortBuilders.fieldSort("created").unmappedType("long").order();

that was exactly the point of this issue. So now it is possible to do

import org.springframework.data.elasticsearch.core.query.Order;

Sort sort = Sort.by(new Order(Sort.Direction.ASC, "created").withUnmappedType("long"));

and use that sort in a Pageable as parameter or whatever.

How is this date field mapped in your index? Is it really unmapped? What does /<indexname>/_mappings show for that property? If you have data for that property in the index then it will be surely mapped, so adding an unmapped type to a sort has not effect. What is the problem that you have with the sorting?

As for the temporal types: java.util.Date is an instance in time in UTC time zone. A LocalDateTime does not have a timezone, so it cannot be instantiated from a long. The appropriate data type would be java.time.Instant

0reactions
alan-czajkowskicommented, Mar 20, 2022

@sothawo I’m using Spring 5.3 and Spring Data ES 4.3

I, personally, think it is reasonable to make java.time.Instant behave like java.util.Date since they are very closely related and because, from an engineering stand-point, normalizing your date-time’s to UTC is actually good practice, as the default behaviour … of course, the default isn’t always desired, but some default can be reasonable … but since this is a “bigger” problem that falls under the Spring Data umbrella (not just Spring Data Elasticsearch) then I’m not about to fight for this since it’s not a battle I have time for

  1. would this be a reasonable definition for my “created” field, given that I want all date-times stored in ES normalized to UTC:
  @Field(type = FieldType.Date, format = DateFormat.epoch_millis)
  private Instant created;
  1. do you recommend that every field have an explicit @Field annotation?
Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple Custom Sorting in Elastic Search - Elasticsearch
You can provide multiple sort clauses to indicate what the primary, secondary, etc sort order should be. And because the sort clause can...
Read more >
ElasticSearch: sort in specific order - Stack Overflow
i have an indexed string field in my docs with letters a-z as possible values. Is it possible to sort ...
Read more >
Custom Sorting with Parameters in Tableau - Evolytics
The Sort By and Sort Order parameters can conveniently be placed anywhere on the dashboard to provide a streamlined user experience.
Read more >
42 Elasticsearch Query Examples - Tutorial - Coralogix
Let's see what happens when we provide the operator parameter “AND” in ... When there is no sort parameter specified in the search...
Read more >
MongoDB Sorting: sort() Method & Examples - BMC Software
Database sorting presents data in an ascending or descending order with relation to the data in a specified field. You can carry out...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found