Skip to content

Commit d4b9499

Browse files
DOC-5110 started hash examples
1 parent b4ab052 commit d4b9499

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

content/develop/clients/jedis/queryjson.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ categories:
99
- oss
1010
- kubernetes
1111
- clients
12-
description: Learn how to use the Redis query engine with JSON
13-
linkTitle: Index and query JSON
14-
title: Example - Index and query JSON documents
12+
description: Learn how to use the Redis query engine with JSON and hash documents.
13+
linkTitle: Index and query documents
14+
title: Index and query documents
1515
weight: 2
1616
---
1717

@@ -70,5 +70,35 @@ to count all users in each city.
7070
{{< clients-example java_home_json query3 >}}
7171
{{< /clients-example >}}
7272

73+
## Differences with hash documents
74+
75+
Indexing for hash documents is very similar to JSON indexing but you
76+
need to specify some slightly different options.
77+
78+
When you create the schema for a hash index, you don't need to
79+
add aliases for the fields, since you use the basic names to access
80+
the fields anyway. Also, you must use `HASH` for the `IndexType`
81+
when you create the index. The code below shows these changes with
82+
a new index called `hash-idx:users`, which is otherwise the same as
83+
the `idx:users` index used for JSON documents in the previous examples.
84+
85+
{{< clients-example java_home_json make_hash_index >}}
86+
{{< /clients-example >}}
87+
88+
Use [`hset()`]({{< relref "/commands/hset" >}}) to add the hash
89+
documents instead of [`jsonSet()`]({{< relref "/commands/json.set" >}}).
90+
91+
{{< clients-example java_home_json add_hash_data >}}
92+
{{< /clients-example >}}
93+
94+
The query commands work the same here for hash as they do for JSON (but
95+
the name of the hash index is different). The results are returned in
96+
a `List` of `Document` objects, as with JSON:
97+
98+
{{< clients-example java_home_json query1_hash >}}
99+
{{< /clients-example >}}
100+
101+
## More information
102+
73103
See the [Redis query engine]({{< relref "/develop/interact/search-and-query" >}}) docs
74104
for a full description of all query features with examples.

0 commit comments

Comments
 (0)