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
Copy file name to clipboardExpand all lines: docs/003-create-index.md
+19-19
Original file line number
Diff line number
Diff line change
@@ -4,26 +4,26 @@ Before creating the index let's describe the dataset and insert entries.
4
4
5
5
## Sample Dataset
6
6
7
-
In this project you will use a simple dataset describging movies, for now, all record are in English. You will learn more about other languages in another tutorial.
7
+
In this project you will use a simple dataset describing movies, for now, all records are in English. You will learn more about other languages in another tutorial.
8
8
9
9
A movie is represented by the following attributes:
10
10
11
11
***`movie_id`** : The unique ID of the movie, internal to this database
12
12
***`title`** : The title of the movie.
13
13
***`plot`** : A summary of the movie.
14
-
***`genre`** : The genre of the movie, for now a movie will only h ave one single genre.
15
-
***`release_year`** : The year the movie has been released as a numerical value.
16
-
***`rating`** : The ratings from the public numerical value.
14
+
***`genre`** : The genre of the movie, for now a movie will only have a single genre.
15
+
***`release_year`** : The year the movie was released as a numerical value.
16
+
***`rating`** : A numeric value representing the public's rating for this movie.
17
17
***`votes`** : Number of votes.
18
18
***`poster`** : Link to the movie poster.
19
19
***`imdb_id`** : id of the movie in the [IMDB](https://imdb.com) database.
20
20
21
21
22
22
### Key and Data structure
23
23
24
-
As a Redis developer, one of the first thing to look when building your application is to define the structure of the key and data (data design/data modeling).
24
+
As a Redis developer, one of the first things to look when building your application is to define the structure of the key and data (data design/data modeling).
25
25
26
-
A common way of defining the keys in Redis is to use specific pattern in them for example in this application when the database will probably deal with various business objects: movies, actors, theaters, users, ... we can use the following pattern:
26
+
A common way of defining the keys in Redis is to use specific patterns in them. For example in this application where the database will probably deal with various business objects: movies, actors, theaters, users, ... we can use the following pattern:
27
27
28
28
*`business_object:key`
29
29
@@ -32,14 +32,14 @@ For example:
32
32
*`user:001` the user with the id 001
33
33
34
34
35
-
and for the movies information you should use a Rediss [Hashes](https://redis.io/topics/data-types#hashes).
35
+
and for the movies information you should use a Redis [Hash](https://redis.io/topics/data-types#hashes).
36
36
37
-
A Redis Hash will allow the application to structure all the movie attributes in individual field; also RediSearch will index the fields based on the index definition.
37
+
A Redis Hash allows the application to structure all the movie attributes in individual fields; also RediSearch will index the fields based on the index definition.
38
38
39
39
## Insert Movies
40
40
41
41
42
-
It is time now to add some data into your database, let's insert few movies, using `redis-cli` or [Redis Insight](https://redislabs.com/redisinsight/).
42
+
It is time now to add some data into your database, let's insert a few movies, using `redis-cli` or [Redis Insight](https://redislabs.com/redisinsight/).
43
43
44
44
Once you are connected to your Redis instance run the following commands:
45
45
@@ -55,7 +55,7 @@ Once you are connected to your Redis instance run the following commands:
55
55
56
56
```
57
57
58
-
Now it is possible to get information from the hash using the movie ID for example if you want to get the title, and rating execute the following command:
58
+
Now it is possible to get information from the hash using the movie ID. For example if you want to get the title, and rating execute the following command:
59
59
60
60
```
61
61
> HMGET movie:11002 title rating
@@ -71,23 +71,23 @@ And you can increment the rating of this movie using:
71
71
"8.8"
72
72
```
73
73
74
-
But how do you get a movie or list of movies from the release year, rating value or title?
74
+
But how do you get a movie or list of movies by year of release, rating or title?
75
75
76
-
One option, would be to read all the movies, check all fields and then return the movies; no need to say that it is a really bad idea.
76
+
One option, would be to read all the movies, check all fields and then return only matching movies; no need to say that this is a really bad idea.
77
77
78
-
Nevertheless this is where Redis developer are creating custom secondary index using SET/SORTED SET structures that point back to the movie hash. This needs some heavy design and implementation.
78
+
Nevertheless this is where Redis developers often create custom secondary indexes using SET/SORTED SET structures that point back to the movie hash. This needs some heavy design and implementation.
79
79
80
-
This is where RediSearch module is helping, and why it as been created.
80
+
This is where the RediSearch module can help, and why it was created.
81
81
82
82
83
83
## RediSearch & Indexing
84
84
85
85
86
-
RediSearch simplifies a lot this by offering a simple and automatic way to create secondary indices on Redis Hashes. (more datastructure will eventually come)
86
+
RediSearch greatly simplifies this by offering a simple and automatic way to create secondary indices on Redis Hashes. (more datastructure will eventually come)
Using RediSearch if you want to query on a field, you must index the fields. Let's start by indexing the following fields in of our movies:
90
+
Using RediSearch if you want to query on a field, you must first index that field. Let's start by indexing the following fields for our movies:
91
91
92
92
* Title
93
93
* Release Year
@@ -101,7 +101,7 @@ When creating a index you define:
101
101
102
102
> ***Warning: Do not index all fields***
103
103
>
104
-
> Indexes take space in memory, and must be updated when the primary data is updated. So create the index carefully and keep the definition up to date with your need.
104
+
> Indexes take space in memory, and must be updated when the primary data is updated. So create the index carefully and keep the definition up to date with your needs.
105
105
106
106
### Create the Index
107
107
@@ -115,9 +115,9 @@ Before running some queries let's look at the command in detail:
115
115
116
116
*[`FT.CREATE`](https://oss.redislabs.com/redisearch/master/Commands/#ftcreate) : creates an index with the given spec. The index name will be used in all the key names so keep it short.
117
117
*`idx:movie` : the name of the index
118
-
*`ON hash` : the type of structure to be indexed. *Note that in RediSearch 2.0 only hash structure are supported, this is parameter will allow RediSearch to index other structure in the future*
118
+
*`ON hash` : the type of structure to be indexed. *Note that in RediSearch 2.0 only hash structures are supported, this parameter will accept other Redis data types in future as RediSearch is updated to index them*
119
119
*`PREFIX 1 "movie:"` : the prefix of the keys that should be indexed. This is a list, so since we want to only index movie:* keys the number is 1. Suppose you want to index movies and tv_show that have the same fields, you can use: `PREFIX 2 "movie:" "tv_show:"`
120
-
*`SCHEMA ...`: define the schema, the fields and their type, to index, as you can see in the command, we are using [TEXT](https://oss.redislabs.com/redisearch/Query_Syntax/#a_few_query_examples), [NUMERIC](https://oss.redislabs.com/redisearch/Query_Syntax/#numeric_filters_in_query) and [TAG](https://oss.redislabs.com/redisearch/Query_Syntax/#tag_filters), and [SORTABLE](https://oss.redislabs.com/redisearch/Sorting/) parameters.
120
+
*`SCHEMA ...`: defines the schema, the fields and their type, to index, as you can see in the command, we are using [TEXT](https://oss.redislabs.com/redisearch/Query_Syntax/#a_few_query_examples), [NUMERIC](https://oss.redislabs.com/redisearch/Query_Syntax/#numeric_filters_in_query) and [TAG](https://oss.redislabs.com/redisearch/Query_Syntax/#tag_filters), and [SORTABLE](https://oss.redislabs.com/redisearch/Sorting/) parameters.
121
121
122
122
You can find information about the [FT.CREATE](https://oss.redislabs.com/redisearch/Commands/#ftcreate) command in the [documentation](https://oss.redislabs.com/redisearch/Commands/#ftcreate).
0 commit comments