Search in sources :

Example 1 with MoreLikeThisQuery

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;
}
Also used : MoreLikeThisQuery(org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery)

Example 2 with MoreLikeThisQuery

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);
}
Also used : MoreLikeThisQuery(org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery) SearchPage(org.springframework.data.elasticsearch.core.SearchPage) Page(org.springframework.data.domain.Page)

Aggregations

MoreLikeThisQuery (org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery)2 Page (org.springframework.data.domain.Page)1 SearchPage (org.springframework.data.elasticsearch.core.SearchPage)1