私はElasticsearchTemplateを初めて使用しています。私は私の質問に基づいてElasticsearchから1000の文書を得たいと思っています。 私はQueryBuilderを使用してクエリを作成しましたが、それは完全に機能しています。 以下のリンクをたどりました。スキャンとスクロールを使用して大きなデータセットを達成することは可能です。
link one
link twoElasticsearchTemplateは大きなデータセットを取得します
私はコピー上記のリンクの1、から貼り付けているコードの次のセクションでこの機能を実装しようとしています。 しかし、私は次のようなエラーになっています:
The type ResultsMapper is not generic; it cannot be parameterized with arguments <myInputDto>.
MyInputDto
は私のプロジェクトで@Document
のアノテーションを持つクラスです。 最後に、私はElasticsearchから1000の文書を検索したいだけです。 size
パラメータを検索しようとしましたが、サポートされていないと思います。
String scrollId = esTemplate.scan(searchQuery, 1000, false);
List<MyInputDto> sampleEntities = new ArrayList<MyInputDto>();
boolean hasRecords = true;
while (hasRecords) {
Page<MyInputDto> page = esTemplate.scroll(scrollId, 5000L,
new ResultsMapper<MyInputDto>() {
@Override
public Page<MyInputDto> mapResults(SearchResponse response) {
List<MyInputDto> chunk = new ArrayList<MyInputDto>();
for (SearchHit searchHit : response.getHits()) {
if (response.getHits().getHits().length <= 0) {
return null;
}
MyInputDto user = new MyInputDto();
user.setId(searchHit.getId());
user.setMessage((String) searchHit.getSource().get("message"));
chunk.add(user);
}
return new PageImpl<MyInputDto>(chunk);
}
});
if (page != null) {
sampleEntities.addAll(page.getContent());
hasRecords = page.hasNextPage();
} else {
hasRecords = false;
}
}
ここで問題は何ですか? これを達成するための他の方法はありますか? 誰かがこのコード(コード)がバックエンドでどのように働いているか教えていただければ幸いです。