Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:06,360 --> 00:00:10,890
So before we can talk about elastic search, we need to talk about rest and RESTful APIs,
2
00:00:10,890 --> 00:00:16,410
the reason is that elastic search is built on top of a RESTful interface and that means to communicate
3
00:00:16,410 --> 00:00:17,690
with elastic search,
4
00:00:17,760 --> 00:00:22,640
you need to communicate with it through http requests that adhere to a rest interface.
5
00:00:22,650 --> 00:00:25,320
So let's talk about what that means.
6
00:00:25,470 --> 00:00:28,920
So let's talk about a http requests at a more high level here.
7
00:00:28,920 --> 00:00:34,200
So whenever you request a web page from your browser what's going on is that your web browser is sending
8
00:00:34,200 --> 00:00:39,150
an http request to a web server somewhere, requesting the contents of that web page that you want to
9
00:00:39,150 --> 00:00:44,010
look at, and elastic search works the same way so instead of talking to a web server, you're talking to
10
00:00:44,010 --> 00:00:45,340
an elastic search server
11
00:00:45,480 --> 00:00:47,500
but it's the same exact protocol.
12
00:00:47,730 --> 00:00:51,480
Now a http request contains a bunch of different stuff, more than you might think.
13
00:00:51,480 --> 00:00:54,270
One is the method and that's basically the verb of the request,
14
00:00:54,270 --> 00:00:59,490
what you're asking the server to do. So in the case of actually getting a web page back from a web server,
15
00:00:59,750 --> 00:01:04,370
you'd be sending a get request saying that I want to get information back from the server,
16
00:01:04,379 --> 00:01:07,240
I'm not going to change anything or any information on the server,
17
00:01:07,380 --> 00:01:09,660
I just want to get information back from it.
18
00:01:09,660 --> 00:01:14,490
You might also have a post verb that means that you want to either insert or replace data that's stored
19
00:01:14,490 --> 00:01:18,960
on the server, or put which means to always create new data on the server or you can even send a delete
20
00:01:18,960 --> 00:01:23,910
verb that means to remove information from the server. Normally, you wouldn't be doing that from a web browser
21
00:01:23,940 --> 00:01:25,930
but from elastic search client,
22
00:01:26,070 --> 00:01:27,900
totally a valid thing to do.
23
00:01:27,900 --> 00:01:29,180
It also includes a protocol.
24
00:01:29,190 --> 00:01:33,060
So specifically, what version of http are you sending this request in?
25
00:01:33,060 --> 00:01:36,150
Might be http slash one point one, for example.
26
00:01:36,150 --> 00:01:38,580
You will be sending that request to a specific host of course,
27
00:01:38,580 --> 00:01:43,890
so if you're requesting a web page from our Web site that might be Sundog dash education dot com, and
28
00:01:43,890 --> 00:01:48,820
the URL is basically what resource you are requesting from that server, what you want that server to
29
00:01:48,810 --> 00:01:49,220
do.
30
00:01:49,350 --> 00:01:54,720
So in the case, again, of a web server that might be the path to the web page that you want on that host.
31
00:01:54,840 --> 00:01:59,310
There's also a request body you can send along, you don't normally see that with a web page request but
32
00:01:59,580 --> 00:02:04,500
you can send extra data along in whatever structured data you want to the server within the body of
33
00:02:04,500 --> 00:02:05,870
that request as well,
34
00:02:05,880 --> 00:02:10,470
and finally, there are headers associated with each request that contain sort of metadata about the request
35
00:02:10,470 --> 00:02:13,560
itself, for example information about the client itself,
36
00:02:13,560 --> 00:02:15,750
that would be in the user region for a web browser,
37
00:02:15,750 --> 00:02:20,920
what format the body is in that might be in the content type, stuff like that.
38
00:02:21,270 --> 00:02:25,410
So let's look at a concrete example, again getting back to the example of a browser wanting to display
39
00:02:25,410 --> 00:02:26,010
a Web site,
40
00:02:26,010 --> 00:02:29,370
this is what a http request for that might contain.
41
00:02:29,370 --> 00:02:34,650
In that example, we're sending a get verb to our web server and we're requesting the resource slash index
42
00:02:34,650 --> 00:02:38,030
dot html from the server meaning we want to get the home page.
43
00:02:38,190 --> 00:02:43,440
We will say that we are sending this in one point one http protocol, and we are sending it to a specific
44
00:02:43,440 --> 00:02:46,680
host and that's our Web site sundog education dot com.
45
00:02:46,710 --> 00:02:51,540
In this example, there is no body being sent across because all the information we need to fulfill this
46
00:02:51,540 --> 00:02:56,100
request has already been specified and there'll be a whole slew of headers being sent along as well
47
00:02:56,220 --> 00:02:58,610
that contains information about the browser itself,
48
00:02:58,710 --> 00:03:02,610
what type of information and languages it can accept back in return from the server,
49
00:03:02,610 --> 00:03:06,090
information about caching, cookies that might be associated with this site,
50
00:03:06,090 --> 00:03:06,790
things like that.
51
00:03:06,810 --> 00:03:10,890
So a bunch of information about you being sent around the internet whenever you request a web page,
52
00:03:10,890 --> 00:03:15,090
but fortunately with elastic search, our use of headers is pretty minimal.
53
00:03:17,210 --> 00:03:21,620
So with that, let's talk about a RESTful APIs, now that we understand http requests.
54
00:03:21,710 --> 00:03:27,190
So the really pragmatic practical definition of a RESTful API is simply that you're using http requests
55
00:03:27,200 --> 00:03:29,990
to communicate with your web service of some sort.
56
00:03:29,990 --> 00:03:36,500
So because we're communicating with elastic search using http requests and responses, that means that
57
00:03:36,500 --> 00:03:38,180
we're basically using a RESTful API.
58
00:03:38,180 --> 00:03:39,190
Now there's more to it than that,
59
00:03:39,200 --> 00:03:40,470
you know, we'll get to that.
60
00:03:40,610 --> 00:03:43,340
But, at a very simple level, that's all it is,
61
00:03:43,430 --> 00:03:45,320
you know, it sounds fancy but that's really it.
62
00:03:45,350 --> 00:03:50,510
So for example, if I want to get information back from my elastic search cluster like search results
63
00:03:50,510 --> 00:03:52,450
for example, I'm actually conducting a search,
64
00:03:52,580 --> 00:03:57,470
I would send a get verb along with that request saying I want to get this information from elastic search.
65
00:03:57,760 --> 00:03:59,570
If I want to insert information into it,
66
00:03:59,630 --> 00:04:01,400
I would send a put request instead,
67
00:04:01,400 --> 00:04:04,860
and the information that I'm inserting would be within the request body,
68
00:04:05,050 --> 00:04:09,260
and if I want to actually remove information from my elastic search index, I would send a delete request
69
00:04:09,260 --> 00:04:11,220
to get rid of it.
70
00:04:11,390 --> 00:04:13,220
Malika said there's more to rest than that,
71
00:04:13,580 --> 00:04:16,930
so let's get into the more the computer science the aspect of it.
72
00:04:17,089 --> 00:04:20,220
Rest stands for a representational state transfer,
73
00:04:20,420 --> 00:04:25,610
and it has six guiding constraints and well, to be honest, these aren't really constraints, not all of
74
00:04:25,610 --> 00:04:26,840
them, some of them are a little bit fuzzy -
75
00:04:26,870 --> 00:04:28,150
we'll talk about that.
76
00:04:28,220 --> 00:04:31,280
Obviously, it needs to be a client server architecture we're dealing with.
77
00:04:31,310 --> 00:04:36,080
You know, the concept of sending requests and responses from clients to servers doesn't really make sense
78
00:04:36,080 --> 00:04:39,920
unless we're talking about client server architecture, and that is what elastic search offers.
79
00:04:39,920 --> 00:04:45,350
We have an elastic search server or maybe even a whole cluster of servers and several clients that are
80
00:04:45,350 --> 00:04:47,480
interacting with that server.
81
00:04:47,480 --> 00:04:48,840
It must be stateless.
82
00:04:48,860 --> 00:04:52,790
That means that every request and response must be self-contained,
83
00:04:52,790 --> 00:04:57,770
you can't assume that there's any memory on the client or the server of the sequence of events that
84
00:04:57,770 --> 00:05:02,480
have happened there really, so you have to make sure that all the information you need to fulfill a request
85
00:05:02,510 --> 00:05:05,180
is contained within the request itself,
86
00:05:05,180 --> 00:05:08,200
and you're not keeping track of state between different requests.
87
00:05:08,510 --> 00:05:13,490
Casheability, this is more of a fuzzy one, it doesn't mean that your responses need to be cached on the
88
00:05:13,490 --> 00:05:14,240
client,
89
00:05:14,240 --> 00:05:16,550
it just means that the system allows for that.
90
00:05:16,610 --> 00:05:21,980
So, maybe your responses include information about whether or not that information can be cached.
91
00:05:22,070 --> 00:05:27,260
Again, not really requirement, but it's on this list of rest constraints. Layered system,
92
00:05:27,260 --> 00:05:32,530
again, not a requirement, but it just means that when you talk to, for example, Sun Dog education dot com,
93
00:05:32,750 --> 00:05:35,740
that doesn't mean you're talking to a specific individual server.
94
00:05:35,810 --> 00:05:39,850
That request might get routed behind the scenes to one of an entire fleet of servers,
95
00:05:39,860 --> 00:05:44,160
so you can't assume that your request is going to a specific physical host,
96
00:05:44,180 --> 00:05:48,410
and again this is why statelessness is important because one host might not know what's going on in
97
00:05:48,410 --> 00:05:51,990
the other necessarily, so they might not be talking to each other really.
98
00:05:52,130 --> 00:05:54,940
Another sort of fuzzy constraint is code on demand,
99
00:05:54,980 --> 00:06:00,590
and this just means that you have the capability of sending code across as a payload on your responses.
100
00:06:00,590 --> 00:06:06,170
So for example, a server might send back javascript code as part of its response body that could then
101
00:06:06,170 --> 00:06:09,560
inform the client how to actually process that data.
102
00:06:09,560 --> 00:06:13,670
We're not actually going to be doing that with elastic search obviously, but rest says you can do that
103
00:06:13,670 --> 00:06:14,860
if you want to.
104
00:06:14,870 --> 00:06:17,910
And finally, it demands a uniform interface,
105
00:06:17,990 --> 00:06:23,750
and what that means is a pretty long topic but, at a fundamental level it just means that your data that
106
00:06:23,750 --> 00:06:28,550
you're sending along is of some structured nature that is predictable and, you know, you can deal with
107
00:06:28,550 --> 00:06:30,960
changes to it in a structured way.
108
00:06:30,980 --> 00:06:33,200
So, at a high level, that's all it is.
109
00:06:33,260 --> 00:06:36,860
With that out of the way, why are we talking about rest at all here?
110
00:06:36,860 --> 00:06:41,270
Well the reason is that we're going to do this whole course just talking about the http requests and
111
00:06:41,270 --> 00:06:47,600
responses themselves, and by dealing with that very low level of how the RESTful API itself of elastic
112
00:06:47,600 --> 00:06:52,820
search works, we can avoid getting mired into the details of how any specific language or system might
113
00:06:52,820 --> 00:06:56,750
be interacting with elastic search. Pretty much any language out there,
114
00:06:56,750 --> 00:07:02,510
Java, Javascript, Python, whatever you want to use is going to have some way of sending http requests,
115
00:07:02,510 --> 00:07:05,130
so it really doesn't matter what language you're using.
116
00:07:05,270 --> 00:07:09,920
What matters more, is understanding how to use elastic search, is how to construct these requests, and
117
00:07:09,920 --> 00:07:12,350
how to interpret the responses that are coming back from it.
118
00:07:12,470 --> 00:07:16,750
The mechanics of how you send that request and get the response back, is trivial,
119
00:07:16,760 --> 00:07:17,060
right?
120
00:07:17,060 --> 00:07:18,620
You know, any language can do that.
121
00:07:18,770 --> 00:07:21,410
If you're a Java developer, you can go look up how to do that.
122
00:07:21,410 --> 00:07:26,270
So we're not going to get mired in the details of how to write a Java client for elastic search,
123
00:07:26,360 --> 00:07:32,750
instead what we're going to teach you in this course, is how to construct http requests and pass the responses
124
00:07:32,750 --> 00:07:35,160
you get back from elastic search in a meaningful way,
125
00:07:35,240 --> 00:07:39,590
and by doing that, you'll be able to transfer this knowledge to any language, in any system that you want,
126
00:07:39,770 --> 00:07:40,870
very easily.
127
00:07:41,030 --> 00:07:45,620
Some languages may have a dedicated client library for elastic search that provide sort of a higher
128
00:07:45,620 --> 00:07:51,580
level wrapper over the actual http requests and responses, but they'll generally be a pretty thin wrapper
129
00:07:51,590 --> 00:07:56,780
so you still need to understand what's going on under the hood, to use elastic serve successfully. A lot of
130
00:07:56,810 --> 00:07:58,270
people get confused on that in this course,
131
00:07:58,280 --> 00:08:03,170
but there's a very good reason for why we're just focusing on the actual http requests and responses,
132
00:08:03,500 --> 00:08:07,650
and not the details of how to do it from a very specific language. All elastic search
133
00:08:07,670 --> 00:08:11,880
documentation is done in the same style, the books that you can find about elastic search,
134
00:08:11,900 --> 00:08:12,550
same idea,
135
00:08:12,560 --> 00:08:18,300
there's a good reason for that. So, the way we're going to interact with elastic search in this course
136
00:08:18,300 --> 00:08:20,490
is just using the curl command on a command line.
137
00:08:20,520 --> 00:08:25,500
So again, instead of using any specific programming language or client library, we're just gonna use curl,
138
00:08:25,500 --> 00:08:29,390
which is a Linux command for sending http requests right from the command line.
139
00:08:29,390 --> 00:08:34,169
So we're just going to bash out curl commands to send out requests on the fly to our service and get the
140
00:08:34,169 --> 00:08:36,440
responses back, and see what comes back from them.
141
00:08:36,480 --> 00:08:38,640
The structure of a curl command looks like this.
142
00:08:38,640 --> 00:08:39,470
Basically, it's curl
143
00:08:39,470 --> 00:08:41,970
dash H, followed by any headers you need to send,
144
00:08:42,120 --> 00:08:47,920
and for elastic search that will always be content type of application slash json, meaning that whatever
145
00:08:47,920 --> 00:08:51,290
is in the body is going to be interpreted as json format,
146
00:08:51,300 --> 00:08:55,560
it will always be that, and in fact we're gonna show you a little bit of a hack on how to always make
147
00:08:55,560 --> 00:08:58,990
that header specified automatically for you on curl, to save you some typing.
148
00:08:59,130 --> 00:09:03,930
That'll be followed by the URL, which contains both the host that you're saying this request to, and in
149
00:09:03,930 --> 00:09:08,850
this course that will usually be the local host 127.0.0.1, followed by any information
150
00:09:08,850 --> 00:09:11,680
that the server will need to actually fulfill that request.
151
00:09:11,700 --> 00:09:17,080
So, you know, what index do I want to talk to, what data type, what sort of command am I asking it to do?
152
00:09:17,100 --> 00:09:22,680
And finally, we will pass dash d, and then the actual message body within quotes that will be json formatted
153
00:09:22,680 --> 00:09:26,910
data with additional information that the service needs to actually figure out what to give back to
154
00:09:26,910 --> 00:09:29,860
you or what to insert into elastic search.
155
00:09:30,000 --> 00:09:33,000
Let's look at some concrete examples to make that more real.
156
00:09:33,000 --> 00:09:37,980
So the first one, at top here, were basically querying the Shakespeare index for the phrase 'to
157
00:09:37,980 --> 00:09:38,820
be or not to be'.
158
00:09:38,820 --> 00:09:41,500
So let's take a closer look at that curl command and what's in it.
159
00:09:41,550 --> 00:09:47,490
Again, we're saying curl dash H content type application json, that's sending a http header that says that
160
00:09:47,490 --> 00:09:53,460
the data in the body is going to be in json format. Dash X get, means that we're using the get method
161
00:09:53,460 --> 00:09:57,930
or the get verb, depending on your terminology, meaning that we just want to retrieve information back
162
00:09:57,930 --> 00:10:04,080
from elastic search, we're not asking you to change anything... and the URL, as you can see, includes
163
00:10:04,080 --> 00:10:09,570
the host that we're talking to, in this case 127.0.01 which is the local loop back address where
164
00:10:09,570 --> 00:10:15,330
your local host, elastic search runs on port ninety two hundred by default, followed by the index name
165
00:10:15,330 --> 00:10:19,620
which is Shakespeare, and then followed by underscore search, meaning that we want to process
166
00:10:19,620 --> 00:10:25,290
a search query as part of this request. The question mark pretty is a query line parameter, that means
167
00:10:25,290 --> 00:10:29,730
that we want to get the results back in a nicely formatted human readable format, because we're gonna
168
00:10:29,730 --> 00:10:34,530
be looking at it on the command line. And finally, we have the request body itself specified after a dash
169
00:10:34,530 --> 00:10:39,210
D and between single quotes, and if you've never seen json before, this is what it looks like, it's just
170
00:10:39,210 --> 00:10:44,730
a structured data format where each level is contained within curly brackets, so it's always contained
171
00:10:44,730 --> 00:10:50,280
by curly brackets at the top level and then we're saying we have a query level, and within those brackets,
172
00:10:50,280 --> 00:10:55,620
we're saying we have a match phrase command that matches the text entry 'to be or not to be'.
173
00:10:55,650 --> 00:11:01,950
So that is how you would construct a real search query in elastic search, using nothing but a http request.
174
00:11:02,460 --> 00:11:04,860
Another example here, we're going to be inserting data.
175
00:11:05,010 --> 00:11:11,070
So in this one we're using a put verb. Again, to 127.0.0.1 on point ninety two hundred.
176
00:11:11,160 --> 00:11:16,530
This time we're talking to an index called movies and a data type called movie, and it's using a unique
177
00:11:16,560 --> 00:11:23,880
identifier for this new entry called 109487, and under movie I.D 109487 we're including
178
00:11:23,880 --> 00:11:26,120
the following information in the message body.
179
00:11:26,400 --> 00:11:28,490
The genre is actually a list of genres,
180
00:11:28,500 --> 00:11:33,360
and in json that will be a comma delimited list of stuff that's enclosed in square brackets,
181
00:11:33,360 --> 00:11:37,610
so this particular movie is both the IMAX and sci fi categories,
182
00:11:37,620 --> 00:11:41,400
its title is Interstellar, and it came out in the year 2014.
183
00:11:41,400 --> 00:11:45,750
So that's what some real http requests look like, when you're dealing with elastic search.
184
00:11:45,750 --> 00:11:49,740
So now that you know what to expect and how we're actually going to use elastic search and communicate
185
00:11:49,740 --> 00:11:53,350
with it, we can talk more about how elastic search works and what it's all about.
186
00:11:53,370 --> 00:11:54,150
We'll do that next.
20998
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.