You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create an index. In this example, all JSON documents with the key prefix `user:` are indexed. For more information, see [Query syntax]({{< relref "/develop/interact/search-and-query/query/" >}}).
Define indexed fields and their data types using `schema`. Use JSON path expressions to map specific JSON elements to the schema fields.
313
-
314
-
```python
315
-
schema = (
316
-
TextField("$.name", as_name="name"),
317
-
TagField("$.city", as_name="city"),
318
-
NumericField("$.age", as_name="age")
319
-
)
320
-
```
283
+
{{< clients-example py_home_json create_data >}}
284
+
{{< /clients-example >}}
321
285
322
-
Create an index. In this example, all JSON documents with the key prefix `user:` will be indexed. For more information, see [Query syntax]({{< relref "/develop/interact/search-and-query/query/" >}}).
286
+
Define indexed fields and their data types using `schema`. Use JSON path expressions to map specific JSON elements to the schema fields. Then, use the schema to create an index. In this example, all JSON documents with the key prefix `user:` will be indexed. For more information, see [Query syntax]({{< relref "/develop/interact/search-and-query/query/" >}}).
323
287
324
-
```python
325
-
rs = r.ft("idx:users")
326
-
rs.create_index(
327
-
schema,
328
-
definition=IndexDefinition(
329
-
prefix=["user:"], index_type=IndexType.JSON
330
-
)
331
-
)
332
-
# b'OK'
333
-
```
288
+
{{< clients-example py_home_json make_index >}}
289
+
{{< /clients-example >}}
334
290
335
291
Use [`JSON.SET`]({{< baseurl >}}/commands/json.set/) to set each user value at the specified path.
336
292
337
-
```python
338
-
r.json().set("user:1", Path.root_path(), user1)
339
-
r.json().set("user:2", Path.root_path(), user2)
340
-
r.json().set("user:3", Path.root_path(), user3)
341
-
```
293
+
{{< clients-example py_home_json add_data >}}
294
+
{{< /clients-example >}}
342
295
343
296
Let's find user `Paul` and filter the results by age.
0 commit comments