Skip to content

Commit 9127aac

Browse files
DOC-5111 started hash examples
1 parent ad59c44 commit 9127aac

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

content/develop/clients/go/queryjson.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,39 @@ to count all users in each city.
116116
{{< clients-example go_home_json query3 >}}
117117
{{< /clients-example >}}
118118

119+
## Differences with hash documents
120+
121+
Indexing for hash documents is very similar to JSON indexing but you
122+
need to specify some slightly different options.
123+
124+
When you create the schema for a hash index, you don't need to
125+
add aliases for the fields, since you use the basic names to access
126+
the fields anyway. Also, you must use `HASH` for the `IndexType`
127+
when you create the index. The code below shows these changes with
128+
a new index called `hash-idx:users`, which is otherwise the same as
129+
the `idx:users` index used for JSON documents in the previous examples.
130+
131+
{{< clients-example go_home_json make_hash_index >}}
132+
{{< /clients-example >}}
133+
134+
You use [`HSet()`]({{< relref "/commands/hset" >}}) to add the hash
135+
documents instead of [`JSONSet()`]({{< relref "/commands/json.set" >}}),
136+
but the same flat `userX` maps work equally well with either
137+
hash or JSON:
138+
139+
{{< clients-example go_home_json add_hash_data >}}
140+
{{< /clients-example >}}
141+
142+
The query commands work the same here for hash as they do for JSON (but
143+
the name of the hash index is different). The format of the result is
144+
also almost the same except that the fields are returned directly in the
145+
result `Document` object map instead of in an enclosing `json` string
146+
under the key "$":
147+
148+
{{< clients-example go_home_json query1_hash >}}
149+
{{< /clients-example >}}
150+
151+
## More information
152+
119153
See the [Redis query engine]({{< relref "/develop/interact/search-and-query" >}}) docs
120-
for a full description of all query features with examples.
154+
for a full description of all query features with examples.

0 commit comments

Comments
 (0)