use of org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery in project spring-data-elasticsearch by spring-projects.
the class ElasticsearchTemplateCallbackTests method moreLikeThisQuery.
private MoreLikeThisQuery moreLikeThisQuery() {
MoreLikeThisQuery query = new MoreLikeThisQuery();
query.setId("init");
query.addFields("id");
return query;
}
use of org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery in project spring-data-elasticsearch by spring-projects.
the class SimpleElasticsearchRepository method searchSimilar.
@SuppressWarnings("unchecked")
@Override
public Page<T> searchSimilar(T entity, @Nullable String[] fields, Pageable pageable) {
Assert.notNull(entity, "Cannot search similar records for 'null'.");
Assert.notNull(pageable, "'pageable' cannot be 'null'");
MoreLikeThisQuery query = new MoreLikeThisQuery();
query.setId(stringIdRepresentation(extractIdFromBean(entity)));
query.setPageable(pageable);
if (fields != null) {
query.addFields(fields);
}
SearchHits<T> searchHits = execute(operations -> operations.search(query, entityClass, getIndexCoordinates()));
SearchPage<T> searchPage = SearchHitSupport.searchPageFor(searchHits, pageable);
return (Page<T>) SearchHitSupport.unwrapSearchHits(searchPage);
}
Aggregations