Skip to main content

Commands: Querying: How to work with MoreLikeThis query?

To find similar or related documents use the MoreLikeThis method from the commands.

Syntax

MultiLoadResult MoreLikeThis(MoreLikeThisQuery query);
Parameters
queryMoreLikeThisQueryA more like this query definition that will be executed
Return Value
MultiLoadResultInstance of MultiLoadResult containing query Results and Includes (if any).

Example I

// Search for similar documents to 'articles/1'
// using 'Articles/MoreLikeThis' index and search only field 'Body'
MultiLoadResult result = store
.DatabaseCommands
.MoreLikeThis(
new MoreLikeThisQuery
{
IndexName = "Articles/MoreLikeThis",
DocumentId = "articles/1",
Fields = new[] { "Body" }
});

Example II

// Search for similar documents to 'articles/1'
// using 'Articles/MoreLikeThis' index and search only field 'Body'
// where article category is 'IT'
MultiLoadResult result = store
.DatabaseCommands
.MoreLikeThis(
new MoreLikeThisQuery
{
IndexName = "Articles/MoreLikeThis",
DocumentId = "articles/1",
Fields = new[] { "Body" },
AdditionalQuery = "Category:IT"
});