@@ -9,9 +9,9 @@ categories:
9
9
- oss
10
10
- kubernetes
11
11
- 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
15
15
weight : 2
16
16
---
17
17
@@ -70,5 +70,35 @@ to count all users in each city.
70
70
{{< clients-example java_home_json query3 >}}
71
71
{{< /clients-example >}}
72
72
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
+
73
103
See the [ Redis query engine] ({{< relref "/develop/interact/search-and-query" >}}) docs
74
104
for a full description of all query features with examples.
0 commit comments