You are currently browsing legacy 3.0 version of documentation. Click here to switch to the newest 5.1 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Commands: Querying: How to work with Suggestion query?

To take advantage of a suggestion feature use the Suggest method from the commands.


public SuggestionQueryResult suggest(String index, SuggestionQuery suggestionQuery);
index String A name of an index to query.
suggestionQuery SuggestionQuery A suggestion query definition containing all information required to query a specified index.
Return Value
SuggestionQueryResult Result containing an array of all suggestions for executed query


// Get suggestions for 'johne' using 'FullName' field in 'Users/ByFullName' index
SuggestionQuery suggestionQuery = new SuggestionQuery();
SuggestionQueryResult result = store.getDatabaseCommands().suggest("Users/ByFullName", suggestionQuery);

System.out.println("Did you mean?");

for (String suggestion: result.getSuggestions()) {
  System.out.println("\t" + suggestion);
// Did you mean?
//      john
//      jones
//      johnson