I don't know about Specification
s, but Spring provides a bean ElasticsearchOperations
which has a "search" method which accepts org.springframework.data.elasticsearch.core.query.CriteriaQuery
which is similar to standard hibernate Criteria
. Try mapping Specification
to CriteriaQuery
.
@Service
@RequiredArgsConstructor
public class FooService {
private final ElasticsearchOperations elasticsearchTemplate; // autowired bean
public void search() {
Criteria criteria = new Criteria();
criteria.and(new Criteria("foo").is(foo));
criteria.and(new Criteria("bar").in(bars));
CriteriaQuery criteriaQuery = new CriteriaQuery(criteria);
elasticsearchOperations.search(criteriaQuery,
FooElasticEntity.class).stream()
.map(SearchHit::getContent)
.collect(Collectors.toList())
}
}
Also it's worth to note that there is a SearchHitSupport
utility class which adds support for Pageable
.