see on GitHub

Session: How to use MoreLikeThis?

MoreLikeThis is available through advanced() in session operations. This method returns articles similar to the provided input.

Syntax

public <T> T[] moreLikeThis(Class<T> entityClass, Class<? extends AbstractIndexCreationTask> indexCreator, String documentId);

public <T> T[] moreLikeThis(Class<T> entityClass, Class<? extends AbstractIndexCreationTask> indexCreator, MoreLikeThisQuery parameters);

public <T> T[] moreLikeThis(Class<T> entityClass, String index, String documentId);

public <T> T[] moreLikeThis(Class<T> entityClass, Class<? extends AbstractIndexCreationTask> indexCreator, Class<? extends AbstractTransformerCreationTask> transformerClass, String documentId);

public <T> T[] moreLikeThis(Class<T> entityClass, Class<? extends AbstractIndexCreationTask> indexCreator, Class<? extends AbstractTransformerCreationTask> transformerClass, MoreLikeThisQuery parameters);

public <T> T[] moreLikeThis(Class<T> entityClass, String index, String transformer, String documentId);

public <T> T[] moreLikeThis(Class<T> entityClass, String index, String transformer, MoreLikeThisQuery parameters);

Parameters
index String Name of an index on which query will be executed.
documentId String Id of a document for which similarities will be searched.
parameters MoreLikeThisQuery A more like this query definition that will be executed.
Return Value
T[] Array of similar documents returned as entities.

Example I

// Search for similar articles to 'articles/1'
// using 'Articles/MoreLikeThis' index and search only field 'Body'
MoreLikeThisQuery moreLikeThisQuery = new MoreLikeThisQuery();
moreLikeThisQuery.setIndexName("Articles/MoreLikeThis");
moreLikeThisQuery.setDocumentId("articles/1");
moreLikeThisQuery.setFields(new String[] { "Body" });

Article[] articles = session.advanced()
  .moreLikeThis(Article.class, "Articles/MoreLikeThis", null, moreLikeThisQuery);

Example II

// Search for similar articles to 'articles/1'
// using 'Articles/MoreLikeThis' index and search only field 'Body'
// where article category is 'IT'
MoreLikeThisQuery moreLikeThisQuery = new MoreLikeThisQuery();
moreLikeThisQuery.setIndexName("Articles/MoreLikeThis");
moreLikeThisQuery.setDocumentId("articles/1");
moreLikeThisQuery.setFields(new String[] { "Body" });
moreLikeThisQuery.setAdditionalQuery("Category:IT");
session.advanced().moreLikeThis(Article.class, "Articles/MoreLikeThis", null, moreLikeThisQuery);