ElasticsearchTemplate을 처음 사용합니다. 내 쿼리를 기반으로 Elasticsearch에서 1000 개의 문서를 가져오고 싶습니다. QueryBuilder를 사용하여 쿼리를 작성했지만 완벽하게 작동합니다. 다음 링크를 살펴 보았습니다. 스캔 및 스크롤을 사용하여 큰 데이터 세트를 얻을 수 있다고 나와 있습니다.
link one
link twoElasticsearchTemplate은 큰 데이터 세트를 검색합니다.
나는 위에서 언급 한 내가 링크 중 하나를 붙여 복사본이 코드의 다음 섹션에서이 기능을 구현하려합니다. 그러나 나는 오류 다음 무엇입니까 :
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;
}
}
무엇이 문제입니까? 이것을 달성하기위한 다른 방법이 있습니까? 만약 누군가이 (코드)가 백엔드에서 어떻게 작동하는지 알려 주시면 감사하겠습니다. 당신이 ElasticsearchTemplate
를 사용하려면