Skip to content

Commit 5097e0b

Browse files
DOC-5110 added section headings and other small fixes
1 parent d4b9499 commit 5097e0b

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

content/develop/clients/jedis/queryjson.md

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,50 @@ weight: 2
1717

1818
This example shows how to create a
1919
[search index]({{< relref "/develop/interact/search-and-query/indexing" >}})
20-
for [JSON]({{< relref "/develop/data-types/json" >}}) data and
21-
run queries against the index.
20+
for [JSON]({{< relref "/develop/data-types/json" >}}) documents and
21+
run queries against the index. It then goes on to show the slight differences
22+
in the equivalent code for [hash]({{< relref "/develop/data-types/hashes" >}})
23+
documents.
2224

23-
Make sure that you have Redis Community Edition and `Jedis` installed.
25+
## Initialize
2426

25-
Start by importing dependencies:
27+
Make sure that you have [Redis Community Edition]({{< relref "/operate/oss_and_stack/" >}})
28+
or another Redis server available. Also install the
29+
[Jedis]({{< relref "/develop/clients/jedis" >}}) client library if you
30+
haven't already done so.
31+
32+
Add the following dependencies. All of them are applicable to both JSON and hash,
33+
except for the `Path` and `JSONObject` classes, which are specific to JSON (see
34+
[Path]({{< relref "/develop/data-types/json/path" >}}) for a description of the
35+
JSON path syntax).
2636

2737
{{< clients-example java_home_json import >}}
2838
{{< /clients-example >}}
2939

30-
Connect to the database:
31-
32-
{{< clients-example java_home_json connect >}}
33-
{{< /clients-example >}}
40+
## Create data
3441

3542
Create some test data to add to the database:
3643

3744
{{< clients-example java_home_json create_data >}}
3845
{{< /clients-example >}}
3946

47+
## Add the index
48+
49+
Connect to your Redis database. The code below shows the most
50+
basic connection but see
51+
[Connect to the server]({{< relref "/develop/clients/jedis/connect" >}})
52+
to learn more about the available connection options.
53+
54+
{{< clients-example java_home_json connect >}}
55+
{{< /clients-example >}}
56+
4057
Create an index. In this example, only JSON documents with the key prefix `user:` are indexed. For more information, see [Query syntax]({{< relref "/develop/interact/search-and-query/query/" >}}).
4158

4259
{{< clients-example java_home_json make_index >}}
4360
{{< /clients-example >}}
4461

62+
## Add the data
63+
4564
Add the three sets of user data to the database as
4665
[JSON]({{< relref "/develop/data-types/json" >}}) objects.
4766
If you use keys with the `user:` prefix then Redis will index the
@@ -50,6 +69,8 @@ objects automatically as you add them:
5069
{{< clients-example java_home_json add_data >}}
5170
{{< /clients-example >}}
5271

72+
## Query the data
73+
5374
You can now use the index to search the JSON objects. The
5475
[query]({{< relref "/develop/interact/search-and-query/query" >}})
5576
below searches for objects that have the text "Paul" in any field
@@ -77,9 +98,9 @@ need to specify some slightly different options.
7798

7899
When you create the schema for a hash index, you don't need to
79100
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
101+
the fields anyway. Also, you must use `IndexDataType.HASH` for the `On()`
102+
option of `FTCreateParams` when you create the index. The code below shows these
103+
changes with a new index called `hash-idx:users`, which is otherwise the same as
83104
the `idx:users` index used for JSON documents in the previous examples.
84105

85106
{{< clients-example java_home_json make_hash_index >}}

0 commit comments

Comments
 (0)