---
title: "Perform a Lazy Query"
url: "https://docs.ravendb.net/6.2/client-api/session/querying/how-to-perform-queries-lazily"
version: "6.2"
language: "java"
---

# Perform a Lazy Query

> Client language: Java. Also available for [C#](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-perform-queries-lazily.md), [Python](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-perform-queries-lazily.python.md), [PHP](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-perform-queries-lazily.php.md), [Node.js](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-perform-queries-lazily.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."

In some situations, query execution must be delayed. To cover such a scenario, `lazily` and many other query extensions have been introduced.

## Lazily

```java
Lazy<List<T>> lazily();

Lazy<List<T>> lazily(Consumer<List<T>> onEval);
```

| Parameters | | |
| - | - | - |
| **onEval** | Consumer\<List\<TResult>> | An action that will be performed on the query results. |

| Return Value | |
| - | - |
| Lazy\<List\<TResult>> | Lazy query initializer returning query results. |

### Example

```java
Lazy<List<Employee>> employeesLazy = session
  .query(Employee.class)
  .whereEquals("FirstName", "Robert")
  .lazily();

List<Employee> employees = employeesLazy.getValue(); // query will be executed here
```

## Counts

```java
Lazy<Integer> countLazily();
```

| Return Value | |
| - | - |
| Lazy\<Integer> | Lazy query initializer returning a count of matched documents. |

### Example

```java
Lazy<Integer> countLazy = session
  .query(Employee.class)
  .whereEquals("FirstName", "Robert")
  .countLazily();

Integer count = countLazy.getValue(); // query will be executed here
```

## Suggestions

```java
Lazy<Map<String, SuggestionResult>> executeLazy();

Lazy<Map<String, SuggestionResult>> executeLazy(Consumer<Map<String, SuggestionResult>> onEval);
```

| Return Value | |
| - | - |
| Lazy\<Map\<String, SuggestionResult>> | Lazy query initializer containing a map with suggestions for matching executed query |

### Example

```java
Lazy<Map<String, SuggestionResult>> suggestLazy = session
  .query(Employee.class, Query.index("Employees_ByFullName"))
  .suggestUsing(builder -> builder.byField("FullName", "johne"))
  .executeLazy();

Map<String, SuggestionResult> suggest = suggestLazy.getValue(); // query will be executed here
List<String> suggestions = suggest.get("FullName").getSuggestions();
```

## Facets

```java
Lazy<Map<String, FacetResult>> executeLazy();

Lazy<Map<String, FacetResult>> executeLazy(Consumer<Map<String, FacetResult>> onEval);
```

| Return Value | |
| - | - |
| Lazy\<Map\<String, FacetResult>> | Lazy query initializer containing a map with facet results matching executed query |

### Example

```java
Lazy<Map<String, FacetResult>> facetsLazy = session
  .query(Camera.class, Query.index("Camera/Costs"))
  .aggregateUsing("facets/CameraFacets")
  .executeLazy();

Map<String, FacetResult> facets = facetsLazy.getValue(); // query will be executed here
FacetResult results = facets.get("manufacturer");
```

## See also

- [Query overview](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-query.md)
- [Perform requests lazily](https://docs.ravendb.net/6.2/client-api/session/how-to/perform-operations-lazily.md)
- [Querying: Basics](https://docs.ravendb.net/6.2/indexes/querying/query-index.java.md)
- [query for suggestions](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-work-with-suggestions.java.md)
