1
votes

Looks like a bug. Sorting works great for simple search, but not working for scroll. I try to do so:

FieldSortBuilder sortTimeCreated = SortBuilders.fieldSort("meta.time_created").order(SortOrder.ASC);
    SearchQuery searchQuery = new NativeSearchQueryBuilder()
                    .withSort(sortTimeCreated)
                    .withQuery(queryBuilder)
                    .withFields("meta.time_created")
                    .withPageable(PageRequest.of(0, 5/*, Sort.Direction.ASC, "meta.time_created"*/)) //was not work
                    .build();
//searchQuery.addSort(Sort.by("meta.time_created").ascending()); //was not work too(used not together with sortTimeCreated)

and after that:

 Page<ElasticRecord> search = elasticsearchTemplate.queryForPage(searchQuery, ElasticRecord.class);
 Page<ElasticRecord> scroll = elasticsearchTemplate.startScroll(30000, searchQuery, ElasticRecord.class);

When running, the application displays:

  1. search:

| DEBUG | o.s.d.elasticsearch.core.QUERY: 937 | {"from":0,"size":5,"query":{"constant_score":{"filter":{...skipped...},"boost":1.0}},"version":true,"_source":{"includes":["meta.time_created"],"excludes":[]},"sort":[{"meta.time_created":{"order":"asc"}}]}

  1. scroll:

| DEBUG | o.s.d.elasticsearch.core.QUERY: 937 | {"from":0,"size":5,"query":{"constant_score":{"filter":{...skipped...},"boost":1.0}},"version":true,"_source":{"includes":["meta.time_created"],"excludes":[]}}

Spring boot (2.1.5.RELEASE(spring-data-elasticsearch 3.1.8.RELEASE), 2.1.2.RELEASE(spring-data-elasticsearch 3.1.8.RELEASE, 3.1.5.RELEASE 3.1.0.RELEASE)

Any ideas?

1

1 Answers

0
votes

This was added in Issue 457 which was merged to the current master on April 24th, 2019. It is available in Spring Data Elasticsearch 3.2.0 M4.