---
title: "Query for Suggestions"
url: "https://docs.ravendb.net/6.2/client-api/session/querying/how-to-work-with-suggestions"
version: "6.2"
language: "java"
---

# Query for Suggestions

> Client language: Java. Also available for [C#](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-work-with-suggestions.md), [Python](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-work-with-suggestions.python.md), [PHP](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-work-with-suggestions.php.md), [Node.js](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-work-with-suggestions.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

The `suggestion` feature is available through query extension methods. It gives you the ability to find word similarities using string distance algorithms.

## Syntax

```java
ISuggestionDocumentQuery<T> suggestUsing(SuggestionBase suggestion);

ISuggestionDocumentQuery<T> suggestUsing(Consumer<ISuggestionBuilder<T>> builder);
```

| Parameters | | |
| - | - | - |
| **suggestion** | `SuggestionBase` | Defines the type of suggestion that should be executed |
| **builder** | `Consumer<ISuggestionBuilder<T>>` | Builder with a fluent API that constructs a `SuggestionBase` instance |

### Builder

```java
ISuggestionOperations<T> byField(String fieldName, String term);

ISuggestionOperations<T> byField(String fieldName, String[] terms);

ISuggestionOperations<T> withOptions(SuggestionOptions options);
```

| Parameters | | |
| - | - | - |
| **fieldName** | String | Points to the index field that should be used for operation |
| **term** | String | Term that will be used as a basis of the suggestions |
| **terms** | String\[] | Terms that will be used as a basis of the suggestions |
| **options** | `SuggestionOptions` | Non-default options that should be used for operation |

### Options

```java
private int pageSize = 15;

private StringDistanceTypes distance = StringDistanceTypes.LEVENSHTEIN;

private Float accuracy = 0.5f;

private SuggestionSortMode sortMode = SuggestionSortMode.POPULARITY;

// getters and setters for fields listed above
```

| Options | | |
| - | - | - |
| **pageSize** | int | Maximum number of suggestions that will be returned |
| **distance** | `StringDistanceTypes` | String distance algorithm to use (`NONE`, `LEVENSTEIN`, `JARO_WINKLER`, `N_GRAM`) |
| **accuracy** | Float | Suggestion accuracy |
| **sortMode** | `SuggestionSortMode` | Indicates in what order the results should be returned (`None`, `Popularity`) |

## Example I

### Java

```java
SuggestionOptions options = new SuggestionOptions();
options.setAccuracy(0.4f);
options.setPageSize(5);
options.setDistance(StringDistanceTypes.JARO_WINKLER);
options.setSortMode(SuggestionSortMode.POPULARITY);

Map<String, SuggestionResult> suggestions = session
  .query(Employee.class, Employees_ByFullName.class)
  .suggestUsing(builder ->
      builder.byField("FullName", "johne")
          .withOptions(options))
  .execute();
```

### RQL

```sql
from index 'Employees/ByFullName' 
select suggest('FullName', 'johne', '{ "Accuracy" : 0.4, "PageSize" : 5, "Distance" : "JaroWinkler", "SortMode" : "Popularity" }')
```

## Example II

### Java

```java
SuggestionWithTerm suggestionWithTerm = new SuggestionWithTerm("FullName");
suggestionWithTerm.setTerm("johne");

Map<String, SuggestionResult> suggestions = session
  .query(Employee.class, Employees_ByFullName.class)
  .suggestUsing(suggestionWithTerm)
  .execute();
```

### RQL

```sql
from index 'Employees/ByFullName' 
select suggest('FullName', 'johne')
```

## See also

- [Querying: Basics](https://docs.ravendb.net/6.2/indexes/querying/query-index.java.md)
- [How to Query](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-query.md)
- [Query for suggestions with index](https://docs.ravendb.net/6.2/indexes/querying/suggestions.java.md)
