{
  "schema_version": 2,
  "id": "develop/clients/lettuce/queryjson",
  "title": "Index and query documents",
  "url": "https://redis.io/docs/latest/develop/clients/lettuce/queryjson/",
  "summary": "Learn how to use Redis Search with JSON and hash documents.",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-10-16T16:25:49+01:00",
  "page_type": "content",
  "content_hash": "cfd7112e4e04245f6a34bc4ff9b07e1d4a7dd92a672dd1dbd4013265d5751641",
  "sections": [
    {
      "id": "initialize",
      "title": "Initialize",
      "role": "content",
      "text": "Make sure that you have [Redis Open Source](https://redis.io/docs/latest/operate/oss_and_stack)\nor another Redis server available. Also install the\n[Lettuce](https://redis.io/docs/latest/develop/clients/lettuce) client library if you\nhaven't already done so.\n\nAdd the following dependencies. All of them are applicable to both JSON and hash,\nexcept for the `JsonParser`, `JsonPath`, and `JsonObject` classes.\n\nFoundational: Import required Lettuce and JSON libraries for querying JSON documents\n\n**Difficulty:** Beginner\n\n**Available in:** Java (Asynchronous - Lettuce), Java (Reactive - Lettuce)\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]"
    },
    {
      "id": "create-data",
      "title": "Create data",
      "role": "content",
      "text": "Create some test data to add to the database:\n\nFoundational: Define sample JSON data structures for users with fields like name, age, and city\n\n**Difficulty:** Beginner\n\n**Available in:** Java (Asynchronous - Lettuce), Java (Reactive - Lettuce)\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]"
    },
    {
      "id": "add-the-index",
      "title": "Add the index",
      "role": "content",
      "text": "Connect to your Redis database. The code below shows the most\nbasic connection but see\n[Connect to the server](https://redis.io/docs/latest/develop/clients/lettuce/connect)\nto learn more about the available connection options.\n\nFoundational: Establish a connection to Redis for executing search and query operations\n\n**Difficulty:** Beginner\n\n**Available in:** Java (Asynchronous - Lettuce), Java (Reactive - Lettuce)\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n\n\nCreate an index. In this example, only JSON documents with the key prefix `user:` are indexed. For more information, see [Query syntax](https://redis.io/docs/latest/develop/ai/search-and-query/query).\n\nFoundational: Create a search index on JSON documents with field mappings and aliases for efficient querying\n\n**Difficulty:** Intermediate\n\n**Available in:** Java (Asynchronous - Lettuce), Java (Reactive - Lettuce)\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]"
    },
    {
      "id": "add-the-data",
      "title": "Add the data",
      "role": "content",
      "text": "Add the three sets of user data to the database as\n[JSON](https://redis.io/docs/latest/develop/data-types/json) objects.\nIf you use keys with the `user:` prefix then Redis will index the\nobjects automatically as you add them:\n\nFoundational: Store JSON documents in Redis using the JSON.SET command with keys matching the index prefix\n\n**Difficulty:** Beginner\n\n**Available in:** Java (Asynchronous - Lettuce), Java (Reactive - Lettuce)\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]"
    },
    {
      "id": "query-the-data",
      "title": "Query the data",
      "role": "content",
      "text": "You can now use the index to search the JSON objects. The\n[query](https://redis.io/docs/latest/develop/ai/search-and-query/query)\nbelow searches for objects that have the text \"Paul\" in any field\nand have an `age` value in the range 30 to 40:\n\nQuery data: Execute a full-text search combined with numeric range filtering to find matching documents\n\n**Difficulty:** Intermediate\n\n**Available in:** Java (Asynchronous - Lettuce), Java (Reactive - Lettuce)\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n\n\nSpecify query options to return only the `city` field:\n\nRestrict query results: Use query options to project specific fields from search results, reducing data transfer\n\n**Difficulty:** Intermediate\n\n**Available in:** Java (Asynchronous - Lettuce), Java (Reactive - Lettuce)\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n\n\nUse an\n[aggregation query](https://redis.io/docs/latest/develop/ai/search-and-query/query/aggregation)\nto count all users in each city.\n\nAggregation: Use aggregation queries to group and count results, performing server-side data analysis\n\n**Difficulty:** Advanced\n\n**Available in:** Java (Asynchronous - Lettuce), Java (Reactive - Lettuce)\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]"
    },
    {
      "id": "differences-with-hash-documents",
      "title": "Differences with hash documents",
      "role": "content",
      "text": "Indexing for hash documents is very similar to JSON indexing but you\nneed to specify some slightly different options.\n\nWhen you create the schema for a hash index, you don't need to\nadd aliases for the fields, since you use the basic names to access\nthe fields. Also, you must use `CreateArgs.TargetType.HASH` for the `On()`\noption of `CreateArgs` when you create the index. The code below shows these\nchanges with a new index called `hash-idx:users`, which is otherwise the same as\nthe `idx:users` index used for JSON documents in the previous examples.\n\nFoundational: Create a search index on hash documents with TargetType.HASH configuration\n\n**Difficulty:** Intermediate\n\n**Available in:** Java (Asynchronous - Lettuce), Java (Reactive - Lettuce)\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n\n\nUse [`hset()`](https://redis.io/docs/latest/commands/hset) to add the hash\ndocuments instead of [`jsonSet()`](https://redis.io/docs/latest/commands/json.set).\n\nFoundational: Store hash documents in Redis using HSET command with keys matching the index prefix\n\n**Difficulty:** Beginner\n\n**Available in:** Java (Asynchronous - Lettuce), Java (Reactive - Lettuce)\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n\n\nThe query commands work the same here for hash as they do for JSON (but\nthe name of the hash index is different). The results are returned in\na `List` of `SearchReply.SearchResult<String, String>` objects, as with JSON:\n\nQuery data: Execute the same search query on hash documents as you would on JSON documents\n\n**Difficulty:** Intermediate\n\n**Available in:** Java (Asynchronous - Lettuce), Java (Reactive - Lettuce)\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]"
    },
    {
      "id": "bulk-import-with-himport",
      "title": "Bulk import with HIMPORT",
      "role": "content",
      "text": "From Redis Open Source 8.10, you can also add the hash documents with the\n[`HIMPORT`](https://redis.io/docs/latest/commands/himport) command family. This creates the same\nhashes as `hset()`, but lets Redis store them as\n[compact hashes](https://redis.io/docs/latest/develop/data-types/hashes#compact-hashes), which use\nless memory when many keys share the same field names. Redis Search indexes\nthese hashes in the same way.\n\nCreate a `HashImport` object with the field names, then create each document\nwith [`himportSet()`](https://redis.io/docs/latest/commands/himport-set), passing only its values,\nin the same order as the field names. Lettuce declares the field names with\n[`HIMPORT PREPARE`](https://redis.io/docs/latest/commands/himport-prepare) the first time you use\nthe `HashImport` object on a connection. Issue all the imports before you wait\nfor any reply, so that Lettuce\n[pipelines](https://redis.io/docs/latest/develop/clients/lettuce/transpipe) them instead of\nwaiting for each reply in turn. With the reactive API, wait for the imports\ninside the `try` block, because a `Mono` that you subscribe to after the\n`HashImport` object closes fails:\n\nBulk ingestion: Import hash documents as compact hashes using a HashImport fieldset and pipelined HIMPORT SET calls\n\n**Difficulty:** Intermediate\n\n**Builds upon:** add_hash_data\n\n**Available in:** Java (Asynchronous - Lettuce), Java (Reactive - Lettuce)\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n\n\n`himportSet()` replaces any existing key, so running this code after the\n`hset()` calls leaves you with the same three documents. The query returns\nthe same result, although the fields can appear in a different order.\n\n> [!NOTE]\n> `HIMPORT` requires Lettuce v7.7.0 or later, and Lettuce marks its support as\n> experimental, so the API might change. Redis Cloud and Redis Software don't\n> support `HIMPORT`."
    },
    {
      "id": "more-information",
      "title": "More information",
      "role": "content",
      "text": "See the [Redis Search](https://redis.io/docs/latest/develop/ai/search-and-query) docs\nfor a full description of all query features with examples."
    }
  ],
  "examples": [
    {
      "id": "initialize-ex0",
      "language": "java",
      "code": "import io.lettuce.core.*;\n\nimport io.lettuce.core.api.async.RedisAsyncCommands;\nimport io.lettuce.core.api.async.RediSearchAsyncCommands;\nimport io.lettuce.core.search.arguments.*;\nimport io.lettuce.core.search.arguments.AggregateArgs.*;\nimport io.lettuce.core.search.SearchReply;\nimport io.lettuce.core.search.AggregationReply;\n\nimport io.lettuce.core.json.JsonParser;\nimport io.lettuce.core.json.JsonObject;\nimport io.lettuce.core.json.JsonPath;\n\nimport io.lettuce.core.api.StatefulRedisConnection;\n\nimport java.util.*;\nimport java.util.concurrent.CompletableFuture;",
      "section_id": "initialize"
    },
    {
      "id": "initialize-ex1",
      "language": "java",
      "code": "import io.lettuce.core.*;\n\nimport io.lettuce.core.api.reactive.RedisReactiveCommands;\nimport io.lettuce.core.api.reactive.RediSearchReactiveCommands;\nimport io.lettuce.core.search.arguments.*;\nimport io.lettuce.core.search.arguments.AggregateArgs.*;\nimport io.lettuce.core.search.SearchReply;\nimport io.lettuce.core.search.AggregationReply;\n\nimport io.lettuce.core.json.JsonParser;\nimport io.lettuce.core.json.JsonObject;\nimport io.lettuce.core.json.JsonPath;\n\nimport io.lettuce.core.api.StatefulRedisConnection;\n\nimport java.util.*;\nimport reactor.core.publisher.Mono;",
      "section_id": "initialize"
    },
    {
      "id": "create-data-ex0",
      "language": "java",
      "code": "JsonParser parser = asyncCommands.getJsonParser();\n\n            JsonObject user1 = parser.createJsonObject().put(\"name\", parser.createJsonValue(\"\\\"Paul John\\\"\"))\n                    .put(\"email\", parser.createJsonValue(\"\\\"paul.john@example.com\\\"\")).put(\"age\", parser.createJsonValue(\"42\"))\n                    .put(\"city\", parser.createJsonValue(\"\\\"London\\\"\"));\n\n            JsonObject user2 = parser.createJsonObject().put(\"name\", parser.createJsonValue(\"\\\"Eden Zamir\\\"\"))\n                    .put(\"email\", parser.createJsonValue(\"\\\"eden.zamir@example.com\\\"\")).put(\"age\", parser.createJsonValue(\"29\"))\n                    .put(\"city\", parser.createJsonValue(\"\\\"Tel Aviv\\\"\"));\n\n            JsonObject user3 = parser.createJsonObject().put(\"name\", parser.createJsonValue(\"\\\"Paul Zamir\\\"\"))\n                    .put(\"email\", parser.createJsonValue(\"\\\"paul.zamir@example.com\\\"\")).put(\"age\", parser.createJsonValue(\"35\"))\n                    .put(\"city\", parser.createJsonValue(\"\\\"Tel Aviv\\\"\"));",
      "section_id": "create-data"
    },
    {
      "id": "create-data-ex1",
      "language": "java",
      "code": "JsonParser parser = reactiveCommands.getJsonParser();\n            JsonObject user1 = parser.createJsonObject().put(\"name\", parser.createJsonValue(\"\\\"Paul John\\\"\"))\n                    .put(\"email\", parser.createJsonValue(\"\\\"paul.john@example.com\\\"\")).put(\"age\", parser.createJsonValue(\"42\"))\n                    .put(\"city\", parser.createJsonValue(\"\\\"London\\\"\"));\n\n            JsonObject user2 = parser.createJsonObject().put(\"name\", parser.createJsonValue(\"\\\"Eden Zamir\\\"\"))\n                    .put(\"email\", parser.createJsonValue(\"\\\"eden.zamir@example.com\\\"\")).put(\"age\", parser.createJsonValue(\"29\"))\n                    .put(\"city\", parser.createJsonValue(\"\\\"Tel Aviv\\\"\"));\n\n            JsonObject user3 = parser.createJsonObject().put(\"name\", parser.createJsonValue(\"\\\"Paul Zamir\\\"\"))\n                    .put(\"email\", parser.createJsonValue(\"\\\"paul.zamir@example.com\\\"\")).put(\"age\", parser.createJsonValue(\"35\"))\n                    .put(\"city\", parser.createJsonValue(\"\\\"Tel Aviv\\\"\"));",
      "section_id": "create-data"
    },
    {
      "id": "add-the-index-ex0",
      "language": "java",
      "code": "RedisClient redisClient = RedisClient.create(\"redis://localhost:6379\");\n\n        try (StatefulRedisConnection<String, String> connection = redisClient.connect()) {\n            RedisAsyncCommands<String, String> asyncCommands = connection.async();\n            RediSearchAsyncCommands<String, String> searchCommands = connection.async();\n            // ...",
      "section_id": "add-the-index"
    },
    {
      "id": "add-the-index-ex1",
      "language": "java",
      "code": "RedisClient redisClient = RedisClient.create(\"redis://localhost:6379\");\n\n        try (StatefulRedisConnection<String, String> connection = redisClient.connect()) {\n            RedisReactiveCommands<String, String> reactiveCommands = connection.reactive();\n            RediSearchReactiveCommands<String, String> searchCommands = connection.reactive();\n            // ...",
      "section_id": "add-the-index"
    },
    {
      "id": "add-the-index-ex2",
      "language": "java",
      "code": "List<FieldArgs<String>> schema = Arrays.asList(TextFieldArgs.<String> builder().name(\"$.name\").as(\"name\").build(),\n                    NumericFieldArgs.<String> builder().name(\"$.age\").as(\"age\").build(),\n                    TagFieldArgs.<String> builder().name(\"$.city\").as(\"city\").build());\n\n            CreateArgs<String, String> createArgs = CreateArgs.<String, String> builder().on(CreateArgs.TargetType.JSON)\n                    .withPrefix(\"user:\").build();\n\n            CompletableFuture<Void> make_index = searchCommands.ftCreate(\"idx:users\", createArgs, schema)\n                    .thenAccept(System.out::println) // >>> OK\n                    .toCompletableFuture();",
      "section_id": "add-the-index"
    },
    {
      "id": "add-the-index-ex3",
      "language": "java",
      "code": "List<FieldArgs<String>> schema = Arrays.asList(TextFieldArgs.<String> builder().name(\"$.name\").as(\"name\").build(),\n                    NumericFieldArgs.<String> builder().name(\"$.age\").as(\"age\").build(),\n                    TagFieldArgs.<String> builder().name(\"$.city\").as(\"city\").build());\n\n            CreateArgs<String, String> createArgs = CreateArgs.<String, String> builder().on(CreateArgs.TargetType.JSON)\n                    .withPrefix(\"user:\").build();\n\n            Mono<Void> make_index = searchCommands.ftCreate(\"idx:users\", createArgs, schema).doOnNext(res -> {\n                System.out.println(res); // >>> OK\n            }).then();",
      "section_id": "add-the-index"
    },
    {
      "id": "add-the-data-ex0",
      "language": "java",
      "code": "CompletableFuture<String> addUser1 = asyncCommands.jsonSet(\"user:1\", JsonPath.ROOT_PATH, user1).thenApply(r -> {\n                System.out.println(r); // >>> OK\n                return r;\n            }).toCompletableFuture();\n\n            CompletableFuture<String> addUser2 = asyncCommands.jsonSet(\"user:2\", JsonPath.ROOT_PATH, user2).thenApply(r -> {\n                System.out.println(r); // >>> OK\n                return r;\n            }).toCompletableFuture();\n\n            CompletableFuture<String> addUser3 = asyncCommands.jsonSet(\"user:3\", JsonPath.ROOT_PATH, user3).thenApply(r -> {\n                System.out.println(r); // >>> OK\n                return r;\n            }).toCompletableFuture();",
      "section_id": "add-the-data"
    },
    {
      "id": "add-the-data-ex1",
      "language": "java",
      "code": "Mono<String> addUser1 = reactiveCommands.jsonSet(\"user:1\", JsonPath.ROOT_PATH, user1).doOnNext(r -> {\n                System.out.println(r); // >>> OK\n            });\n\n            Mono<String> addUser2 = reactiveCommands.jsonSet(\"user:2\", JsonPath.ROOT_PATH, user2).doOnNext(r -> {\n                System.out.println(r); // >>> OK\n            });\n\n            Mono<String> addUser3 = reactiveCommands.jsonSet(\"user:3\", JsonPath.ROOT_PATH, user3).doOnNext(r -> {\n                System.out.println(r); // >>> OK\n            });",
      "section_id": "add-the-data"
    },
    {
      "id": "query-the-data-ex0",
      "language": "java",
      "code": "CompletableFuture<SearchReply<String, String>> query1 = searchCommands.ftSearch(\"idx:users\", \"Paul @age:[30 40]\")\n                    .thenApply(res -> {\n                        List<SearchReply.SearchResult<String, String>> results = res.getResults();\n\n                        results.forEach(result -> {\n                            System.out.println(result.getId());\n                        });\n                        // >>> user:3\n                        return res;\n                    }).toCompletableFuture();",
      "section_id": "query-the-data"
    },
    {
      "id": "query-the-data-ex1",
      "language": "java",
      "code": "Mono<SearchReply<String, String>> query1 = searchCommands.ftSearch(\"idx:users\", \"Paul @age:[30 40]\")\n                    .doOnNext(res -> {\n                        List<SearchReply.SearchResult<String, String>> results = res.getResults();\n\n                        results.forEach(result -> {\n                            System.out.println(result.getId());\n                        });\n                        // >>> user:3\n                    });",
      "section_id": "query-the-data"
    },
    {
      "id": "query-the-data-ex2",
      "language": "java",
      "code": "SearchArgs<String, String> query2Args = SearchArgs.<String, String> builder().returnField(\"city\").build();\n            CompletableFuture<SearchReply<String, String>> query2 = searchCommands.ftSearch(\"idx:users\", \"Paul\", query2Args)\n                    .thenApply(res -> {\n                        List<SearchReply.SearchResult<String, String>> results = res.getResults();\n\n                        results.forEach(result -> {\n                            System.out.printf(\"ID: %s, City: %s\\n\", result.getId(), result.getFields().get(\"city\"));\n                        });\n                        // >>> ID: user:1, City: London\n                        // >>> ID: user:3, City: Tel Aviv\n                        return res;\n                    }).toCompletableFuture();",
      "section_id": "query-the-data"
    },
    {
      "id": "query-the-data-ex3",
      "language": "java",
      "code": "SearchArgs<String, String> query2Args = SearchArgs.<String, String> builder().returnField(\"city\").build();\n\n            Mono<SearchReply<String, String>> query2 = searchCommands.ftSearch(\"idx:users\", \"Paul\", query2Args)\n                    .doOnNext(res -> {\n                        List<SearchReply.SearchResult<String, String>> results = res.getResults();\n\n                        results.forEach(result -> {\n                            System.out.printf(\"ID: %s, City: %s\\n\", result.getId(), result.getFields().get(\"city\"));\n                        });\n                        // >>> ID: user:1, City: London\n                        // >>> ID: user:3, City: Tel Aviv\n                    });",
      "section_id": "query-the-data"
    },
    {
      "id": "query-the-data-ex4",
      "language": "java",
      "code": "AggregateArgs<String, String> aggArgs = AggregateArgs.<String, String> builder()\n                    .groupBy(GroupBy.<String, String> of(\"@city\").reduce(Reducer.<String, String> count().as(\"count\"))).build();\n            CompletableFuture<AggregationReply<String, String>> query3 = searchCommands.ftAggregate(\"idx:users\", \"*\", aggArgs)\n                    .thenApply(res -> {\n                        List<SearchReply<String, String>> replies = res.getReplies();\n                        replies.forEach(reply -> {\n                            reply.getResults().forEach(result -> {\n                                System.out.printf(\"City: %s, Count: %s\\n\", result.getFields().get(\"city\"),\n                                        result.getFields().get(\"count\"));\n                            });\n                            // >>> City: London, Count: 1\n                            // >>> City: Tel Aviv, Count: 2\n                        });\n                        return res;\n                    }).toCompletableFuture();",
      "section_id": "query-the-data"
    },
    {
      "id": "query-the-data-ex5",
      "language": "java",
      "code": "AggregateArgs<String, String> aggArgs = AggregateArgs.<String, String> builder()\n                    .groupBy(GroupBy.<String, String> of(\"@city\").reduce(Reducer.<String, String> count().as(\"count\"))).build();\n\n            Mono<AggregationReply<String, String>> query3 = searchCommands.ftAggregate(\"idx:users\", \"*\", aggArgs)\n                    .doOnNext(res -> {\n                        List<SearchReply<String, String>> replies = res.getReplies();\n                        replies.forEach(reply -> {\n                            reply.getResults().forEach(result -> {\n                                System.out.printf(\"City: %s, Count: %s\\n\", result.getFields().get(\"city\"),\n                                        result.getFields().get(\"count\"));\n                            });\n                            // >>> City: London, Count: 1\n                            // >>> City: Tel Aviv, Count: 2\n                        });\n                    });",
      "section_id": "query-the-data"
    },
    {
      "id": "differences-with-hash-documents-ex0",
      "language": "java",
      "code": "List<FieldArgs<String>> hashSchema = Arrays.asList(TextFieldArgs.<String> builder().name(\"name\").build(),\n                    NumericFieldArgs.<String> builder().name(\"age\").build(),\n                    TagFieldArgs.<String> builder().name(\"city\").build());\n\n            CreateArgs<String, String> hashCreateArgs = CreateArgs.<String, String> builder().on(CreateArgs.TargetType.HASH)\n                    .withPrefix(\"huser:\").build();\n\n            CompletableFuture<Void> makeHashIndex = searchCommands.ftCreate(\"hash-idx:users\", hashCreateArgs, hashSchema)\n                    .thenAccept(System.out::println) // >>> OK\n                    .toCompletableFuture();",
      "section_id": "differences-with-hash-documents"
    },
    {
      "id": "differences-with-hash-documents-ex1",
      "language": "java",
      "code": "List<FieldArgs<String>> hashSchema = Arrays.asList(TextFieldArgs.<String> builder().name(\"name\").build(),\n                    NumericFieldArgs.<String> builder().name(\"age\").build(),\n                    TagFieldArgs.<String> builder().name(\"city\").build());\n\n            CreateArgs<String, String> hashCreateArgs = CreateArgs.<String, String> builder().on(CreateArgs.TargetType.HASH)\n                    .withPrefix(\"huser:\").build();\n\n            Mono<String> makeHashIndex = searchCommands.ftCreate(\"hash-idx:users\", hashCreateArgs, hashSchema).doOnNext(res -> {\n                System.out.println(res); // >>> OK\n            });",
      "section_id": "differences-with-hash-documents"
    },
    {
      "id": "differences-with-hash-documents-ex2",
      "language": "java",
      "code": "Map<String, String> huser1 = new HashMap<>();\n            huser1.put(\"name\", \"Paul John\");\n            huser1.put(\"email\", \"paul.john@example.com\");\n            huser1.put(\"age\", \"42\");\n            huser1.put(\"city\", \"London\");\n\n            Map<String, String> huser2 = new HashMap<>();\n            huser2.put(\"name\", \"Eden Zamir\");\n            huser2.put(\"email\", \"eden.zamir@example.com\");\n            huser2.put(\"age\", \"29\");\n            huser2.put(\"city\", \"Tel Aviv\");\n\n            Map<String, String> huser3 = new HashMap<>();\n            huser3.put(\"name\", \"Paul Zamir\");\n            huser3.put(\"email\", \"paul.zamir@example.com\");\n            huser3.put(\"age\", \"35\");\n            huser3.put(\"city\", \"Tel Aviv\");\n\n            CompletableFuture<Long> addHashUser1 = asyncCommands.hset(\"huser:1\", huser1).thenApply(r -> {\n                System.out.println(r); // >>> 4\n                return r;\n            }).toCompletableFuture();\n\n            CompletableFuture<Long> addHashUser2 = asyncCommands.hset(\"huser:2\", huser2).thenApply(r -> {\n                System.out.println(r); // >>> 4\n                return r;\n            }).toCompletableFuture();\n\n            CompletableFuture<Long> addHashUser3 = asyncCommands.hset(\"huser:3\", huser3).thenApply(r -> {\n                System.out.println(r); // >>> 4\n                return r;\n            }).toCompletableFuture();",
      "section_id": "differences-with-hash-documents"
    },
    {
      "id": "differences-with-hash-documents-ex3",
      "language": "java",
      "code": "Map<String, String> huser1 = new HashMap<>();\n            huser1.put(\"name\", \"Paul John\");\n            huser1.put(\"email\", \"paul.john@example.com\");\n            huser1.put(\"age\", \"42\");\n            huser1.put(\"city\", \"London\");\n\n            Map<String, String> huser2 = new HashMap<>();\n            huser2.put(\"name\", \"Eden Zamir\");\n            huser2.put(\"email\", \"eden.zamir@example.com\");\n            huser2.put(\"age\", \"29\");\n            huser2.put(\"city\", \"Tel Aviv\");\n\n            Map<String, String> huser3 = new HashMap<>();\n            huser3.put(\"name\", \"Paul Zamir\");\n            huser3.put(\"email\", \"paul.zamir@example.com\");\n            huser3.put(\"age\", \"35\");\n            huser3.put(\"city\", \"Tel Aviv\");\n\n            Mono<Long> addHashUser1 = reactiveCommands.hset(\"huser:1\", huser1).doOnNext(r -> {\n                System.out.println(r); // >>> 4\n            });\n\n            Mono<Long> addHashUser2 = reactiveCommands.hset(\"huser:2\", huser2).doOnNext(r -> {\n                System.out.println(r); // >>> 4\n            });\n\n            Mono<Long> addHashUser3 = reactiveCommands.hset(\"huser:3\", huser3).doOnNext(r -> {\n                System.out.println(r); // >>> 4\n            });",
      "section_id": "differences-with-hash-documents"
    },
    {
      "id": "differences-with-hash-documents-ex4",
      "language": "java",
      "code": "CompletableFuture<SearchReply<String, String>> query1Hash = searchCommands\n                    .ftSearch(\"hash-idx:users\", \"Paul @age:[30 40]\").thenApply(res -> {\n                        List<SearchReply.SearchResult<String, String>> results = res.getResults();\n\n                        results.forEach(result -> {\n                            System.out.println(result.getId());\n                        });\n                        // >>> huser:3\n                        return res;\n                    }).toCompletableFuture();",
      "section_id": "differences-with-hash-documents"
    },
    {
      "id": "differences-with-hash-documents-ex5",
      "language": "java",
      "code": "Mono<SearchReply<String, String>> query1Hash = searchCommands.ftSearch(\"hash-idx:users\", \"Paul @age:[30 40]\")\n                    .doOnNext(res -> {\n                        List<SearchReply.SearchResult<String, String>> results = res.getResults();\n\n                        results.forEach(result -> {\n                            System.out.println(result.getId());\n                        });\n                        // >>> huser:3\n                    });",
      "section_id": "differences-with-hash-documents"
    },
    {
      "id": "bulk-import-with-himport-ex0",
      "language": "java",
      "code": "List<RedisFuture<String>> himportUsers = new ArrayList<>();\n\n            try (HashImport<String> fieldset = HashImport.of(\"name\", \"email\", \"age\", \"city\")) {\n                himportUsers.add(asyncCommands.himportSet(\"huser:1\", fieldset,\n                        \"Paul John\", \"paul.john@example.com\", \"42\", \"London\"));\n                himportUsers.add(asyncCommands.himportSet(\"huser:2\", fieldset,\n                        \"Eden Zamir\", \"eden.zamir@example.com\", \"29\", \"Tel Aviv\"));\n                himportUsers.add(asyncCommands.himportSet(\"huser:3\", fieldset,\n                        \"Paul Zamir\", \"paul.zamir@example.com\", \"35\", \"Tel Aviv\"));\n            }\n\n            CompletableFuture<Void> importUsers = CompletableFuture\n                    .allOf(himportUsers.stream().map(RedisFuture::toCompletableFuture).toArray(CompletableFuture[]::new));",
      "section_id": "bulk-import-with-himport"
    },
    {
      "id": "bulk-import-with-himport-ex1",
      "language": "java",
      "code": "try (HashImport<String> fieldset = HashImport.of(\"name\", \"email\", \"age\", \"city\")) {\n                Mono<String> import1 = reactiveCommands.himportSet(\"huser:1\", fieldset,\n                        \"Paul John\", \"paul.john@example.com\", \"42\", \"London\");\n                Mono<String> import2 = reactiveCommands.himportSet(\"huser:2\", fieldset,\n                        \"Eden Zamir\", \"eden.zamir@example.com\", \"29\", \"Tel Aviv\");\n                Mono<String> import3 = reactiveCommands.himportSet(\"huser:3\", fieldset,\n                        \"Paul Zamir\", \"paul.zamir@example.com\", \"35\", \"Tel Aviv\");\n\n                // Subscribe before the fieldset closes.\n                Mono.when(import1, import2, import3).block();\n            }",
      "section_id": "bulk-import-with-himport"
    }
  ]
}
