Skip to content

SearchAfter does not support date types, and all types except string types are cast; Will cause pagination exceptions #2678

Closed
@heerzhang

Description

@heerzhang

There is an issue with sorting and pagination of date fields. If the date is a null value, the searchAfter pagination will stay in place and will not search for new records. The main issue should be in/org/springframework/data/lastsearch/client/elc/RequestConverter. java: 1378 line:

If (! IsEmpty (query. getSearchAfter())){

 Builder. searchAfter(
       query.getSearchAfter().stream().map(it -> FieldValue.of(it.toString())).collect(Collectors.toList()));

}

The code at this point requires that the SortValue of the date type field also be cast to FieldValue. of (it. toString()).

But I feel like I should use FieldValue of (long value) for the date type{

Return new FieldValue (Kind. Long, value);

}Just replace the logic here.

Because the date field returned by getSortValues () is a long integer in string form called 'epoch_millis'.

Even if I take the epoch myself_ Converting Millis to a string formatted with a date [uuuu MM dd] cannot solve the problem, as epoch is returned when date=null_ Millis is an illegal date.

The code is roughly as follows:

ElasticsearchOperations ElasticsearchOperations;

org.springframework.data.elasticsearch.client.elc.NativeQuery query,

List afterObjs=new ArrayList<>(from below lastsortHit. getSortValues());

Query query. setSearchAfter (afterObjs);

SearchHits

searchHits=ElasticsearchOperations. search (query, myClassType);

List<SearchHit

> hits=searchHits. getSearchHits();

SearchHit lastsortHit=hits. get (Maxs-1);
List afterObjs= lastsortHit.getSortValues();

笔记

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions