如何通过elasticsearchrestemplate将搜索请求发送到elastic,并在param之后终止?

mlmc2os5  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(342)

我确实请求使用elasticsearchresttemplate对文档实体进行ElasticCluster。我的刀类:

import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
import org.springframework.data.elasticsearch.core.query.SearchQuery;
import org.springframework.stereotype.Component;
import APP_PACKAGE.dto.request.DocElasticFilterDto;
import APP_PACKAGE.dto.request.DocElasticPaginationDto;
import APP_PACKAGE.model.entity.Document;

@Component
@RequiredArgsConstructor
public class DocumentDao {
    private final ElasticsearchRestTemplate esTemplate;

    @NotNull
    public AggregatedPage search(@NotNull DocElasticFilterDto filter, @NotNull DocElasticPaginationDto pagination) {
        SearchQuery query = DocumentQueryBuilderKt.buildSearchQuery(filter, pagination);
        return esTemplate.queryForPage(query, Document.class);
    }
}

elasticsearchresttemplate发送到此http请求:

curl -iX POST 'http://HOST:9200/INDEX/_doc/_search?rest_total_hits_as_int=true&typed_keys=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&ignore_throttled=true&search_type=dfs_query_then_fetch&batched_reduce_size=512' -d '{"from":0,"size":1,"query":{"bool":{"filter":[{"terms":{"pgs":[2],"boost":1.0}},{"terms":{"t":[2],"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}},"version":true,"sort":[{"t":{"order":"desc"}}]}'

我想发送请求与终止\u后(计算为每个搜索像 from + size (params from pagination dto)param如下:

curl -iX POST 'http://HOST:9200/INDEX/_doc/_search?rest_total_hits_as_int=true&typed_keys=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&ignore_throttled=true&search_type=dfs_query_then_fetch&batched_reduce_size=512&terminate_after=1' -d '{"from":0,"size":1,"query":{"bool":{"filter":[{"terms":{"pgs":[2],"boost":1.0}},{"terms":{"t":[2],"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}},"version":true,"sort":[{"t":{"order":"desc"}}]}'

如何使用spring data elasticsearch实现这一点?

41ik7eoe

41ik7eoe1#

这个 terminate_after spring data elasticsearch当前不支持参数。

相关问题