Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 231 lines (173 sloc) 8.653 kB
b3337c3 @kimchy initial commit
kimchy authored
1 h1. ElasticSearch
2
3 h2. A Distributed RESTful Search Engine
4
5 h3. "http://www.elasticsearch.com":http://www.elasticsearch.com
6
7 ElasticSearch is a distributed RESTful search engine built for the cloud. Features include:
8
9 * Distributed and Highly Available Search Engine.
10 ** Each index is fully sharded with a configurable number of shards.
c31d29b @kimchy fix readme to use replica and not backup for shards
kimchy authored
11 ** Each shard can have one or more replicas.
12 ** Read / Search operations performed on either one of the replica shard.
b3337c3 @kimchy initial commit
kimchy authored
13 * Multi Tenant with Multi Types.
14 ** Support for more than one index.
15 ** Support for more than one type per index.
16 ** Index level configuration (number of shards, index storage, ...).
17 * Various set of APIs
18 ** HTTP RESTful API
19 ** Native Java API.
20 ** All APIs perform automatic node operation rerouting.
21 * Document oriented
22 ** No need for upfront schema definition.
23 ** Schema can be defined per type for customization of the indexing process.
24 * Reliable, Asynchronous Write Behind for long term persistency.
25 * (Near) Real Time Search.
26 * Built on top of Lucene
27 ** Each shard is a fully functional Lucene index
28 ** All the power of Lucene easily exposed through simple configuration / plugins.
29 * Per operation consistency
30 ** Single document level operations are atomic, consistent, isolated and durable.
31 * Open Source under Apache 2 License.
32
33 h2. Getting Started
34
35 Fist of all, DON'T PANIC. It will take 5 minutes to get the gist of what ElasticSearch is all about.
36
37 h3. Installation
38
39 * Download and unzip the ElasticSearch installation.
40 * Run @bin/elasticsearch -f@ on unix, or @bin/elasticsearch.bat@ on windows.
41 * Run @curl -X GET http://localhost:9200/@.
42 * Start more servers ...
43
44 h3. Indexing
45
46 Lets try and index some twitter like information. First, lets create a twitter user, and add some tweets (the @twitter@ index will be created automatically):
47
48 <pre>
54dc5a5 @kimchy update readme file
kimchy authored
49 curl -XPUT 'http://localhost:9200/twitter/user/kimchy' -d '{ name: "Shay Banon" }'
50
51 curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '
52 {
53 "user": "kimchy",
54 "postDate": "2009-11-15T13:12:00",
55 "message": "Trying out Elastic Search, so far so good?"
56 }'
57
58 curl -XPUT 'http://localhost:9200/twitter/tweet/2' -d '
59 {
60 "user": "kimchy",
61 "postDate": "2009-11-15T14:12:12",
62 "message": "Another tweet, will it be indexed?"
63 }'
b3337c3 @kimchy initial commit
kimchy authored
64 </pre>
65
66 Now, lets see if the information was added by GETting it:
67
68 <pre>
54dc5a5 @kimchy update readme file
kimchy authored
69 curl -XGET 'http://localhost:9200/twitter/user/kimchy?pretty=true'
70 curl -XGET 'http://localhost:9200/twitter/tweet/1?pretty=true'
71 curl -XGET 'http://localhost:9200/twitter/tweet/2?pretty=true'
b3337c3 @kimchy initial commit
kimchy authored
72 </pre>
73
74 h3. Searching
75
76 Mmm search..., shouldn't it be elastic?
77 Lets find all the tweets that @kimchy@ posted:
78
79 <pre>
54dc5a5 @kimchy update readme file
kimchy authored
80 curl -XGET 'http://localhost:9200/twitter/tweet/_search?q=user:kimchy&pretty=true'
b3337c3 @kimchy initial commit
kimchy authored
81 </pre>
82
83 We can also use the JSON query language ElasticSearch provides instead of a query string:
84
85 <pre>
54dc5a5 @kimchy update readme file
kimchy authored
86 curl -XGET 'http://localhost:9200/twitter/tweet/_search?pretty=true' -d '
87 {
88 "query" : {
89 "term" : { "user": "kimchy" }
90 }
91 }'
b3337c3 @kimchy initial commit
kimchy authored
92 </pre>
93
94 Just for kicks, lets get all the documents stored (we should see the user as well):
95
96 <pre>
54dc5a5 @kimchy update readme file
kimchy authored
97 curl -XGET 'http://localhost:9200/twitter/_search?pretty=true' -d '
98 {
99 "query" : {
100 "matchAll" : {}
101 }
102 }'
b3337c3 @kimchy initial commit
kimchy authored
103 </pre>
104
105 We can also do range search (the @postDate@ was automatically identified as date)
106
107 <pre>
54dc5a5 @kimchy update readme file
kimchy authored
108 curl -XGET 'http://localhost:9200/twitter/_search?pretty=true' -d '
109 {
110 "query" : {
111 "range" : {
112 "postDate" : { "from" : "2009-11-15T13:00:00", "to" : "2009-11-15T14:00:00" }
113 }
114 }
115 }'
b3337c3 @kimchy initial commit
kimchy authored
116 </pre>
117
118 There are many more options to perform search, after all, its a search product no? All the familiar Lucene queries are available through the JSON query language, or through the query parser.
119
120 h3. Multi Tenant - Indices and Types
121
122 Maan, that twitter index might get big (in this case, index size == valuation). Lets see if we can structure our twitter system a bit differently in order to support such large amount of data.
123
124 ElasticSearch support multiple indices, as well as multiple types per index. In the previous example we used an index called @twitter@, with two types, @user@ and @tweet@.
125
126 Another way to define our simple twitter system is to have a different index per user. Here is the indexing curl's in this case:
127
128 <pre>
54dc5a5 @kimchy update readme file
kimchy authored
129 curl -XPUT 'http://localhost:9200/kimchy/info/1' -d '{ name: "Shay Banon" }'
130
131 curl -XPUT 'http://localhost:9200/kimchy/tweet/1' -d '
132 {
133 "user": "kimchy",
134 "postDate": "2009-11-15T13:12:00",
135 "message": "Trying out Elastic Search, so far so good?"
136 }'
137
138 curl -XPUT 'http://localhost:9200/kimchy/tweet/2' -d '
139 {
140 "user": "kimchy",
141 "postDate": "2009-11-15T14:12:12",
142 "message": "Another tweet, will it be indexed?"
143 }'
b3337c3 @kimchy initial commit
kimchy authored
144 </pre>
145
146 The above index information into the @kimchy@ index, with two types, @info@ and @tweet@. Each user will get his own special index.
147
c31d29b @kimchy fix readme to use replica and not backup for shards
kimchy authored
148 Complete control on the index level is allowed. As an example, in the above case, we would want to change from the default 5 shards with 1 replica per index, to only 1 shard with 1 replica per index (== per twitter user). Here is how this can be done (the configuration can be in yaml as well):
b3337c3 @kimchy initial commit
kimchy authored
149
150 <pre>
54dc5a5 @kimchy update readme file
kimchy authored
151 curl -XPUT http://localhost:9200/another_user/ -d '
152 {
153 "index" : {
154 "numberOfShards" : 1,
155 "numberOfReplicas" : 1
156 }
157 }'
b3337c3 @kimchy initial commit
kimchy authored
158 </pre>
159
160 Search (and similar operations) are multi index aware. This means that we can easily search on more than one
161 index (twitter user), for example:
162
163 <pre>
54dc5a5 @kimchy update readme file
kimchy authored
164 curl -XGET 'http://localhost:9200/kimchy,another_user/_search?pretty=true' -d '
165 {
166 "query" : {
167 "matchAll" : {}
168 }
169 }'
b3337c3 @kimchy initial commit
kimchy authored
170 </pre>
171
172 Or on all the indices:
173
174 <pre>
54dc5a5 @kimchy update readme file
kimchy authored
175 curl -XGET 'http://localhost:9200/_search?pretty=true' -d '
176 {
177 "query" : {
178 "matchAll" : {}
179 }
180 }'
b3337c3 @kimchy initial commit
kimchy authored
181 </pre>
182
183 {One liner teaser}: And the cool part about that? You can easily search on multiple twitter users (indices), with different boost levels per user (index), making social search so much simpler (results from my friends rank higher than results from my friends friends).
184
185 h3. Distributed, Highly Available, and Write Behind
186
187 Lets face it, things will fail....
188
c31d29b @kimchy fix readme to use replica and not backup for shards
kimchy authored
189 ElasticSearch is a highly available and distributed search engine. Each index is broken down into shards, and each shard can have one or more replica. By default, an index is created with 5 shards and 1 replica per shard (5/1). There are many topologies that can be used, including 1/10 (improve search performance), or 20/1 (improve indexing performance, with search executed in a map reduce fashion across shards).
b3337c3 @kimchy initial commit
kimchy authored
190
191 In order to play with Elastic Search distributed nature, simply bring more nodes up and shut down nodes. The system will continue to serve requests (make sure you use the correct http port) with the latest data indexed.
192
193 If the whole cluster is brought down, all the indexed data will be lost (each shard local storage is temporal). For long term persistency, write behind should be enabled. This is as simple as configuring the @elasticsearch.yml@ configuration file (which effectively enables write behind to file system for all indices created unless configured otherwise when creating the index):
194
195 <pre>
196 gateway:
197 type: fs
198 </pre>
199
200 Alternatively, elastic search can be started with the following command line:
c31d29b @kimchy fix readme to use replica and not backup for shards
kimchy authored
201 @elasticsearch -f -Des.gateway.type=fs@.
b3337c3 @kimchy initial commit
kimchy authored
202
203 The above configuration will persist the indices create on ElasticSearch to a file system (path can be configured) in an asynchronous, reliable fashion. Other gateways implementations can be easily implemented and more will be provided out of the box in later versions (did someone say AmazonS3/Hadoop/Cassandra?).
204
205 h3. Where to go from here?
206
207 We have just covered a very small portion of what ElasticSearch is all about. For more information, please refer to: .
208
209 h3. Building from Source
210
54dc5a5 @kimchy update readme file
kimchy authored
211 ElasticSearch uses Gradle:http://www.gradle.org for its build system. In order to create a distribution, simply run @gradlew@, the distribution will be created under @build/distributions@.
b3337c3 @kimchy initial commit
kimchy authored
212
213 h1. License
214
215 <pre>
216 This software is licensed under the Apache 2 license, quoted below.
217
54dc5a5 @kimchy update readme file
kimchy authored
218 Copyright 2009-2010 Shay Banon and ElasticSearch <http://www.elasticsearch.com>
b3337c3 @kimchy initial commit
kimchy authored
219
220 Licensed under the Apache License, Version 2.0 (the "License"); you may not
221 use this file except in compliance with the License. You may obtain a copy of
222 the License at
223
224 http://www.apache.org/licenses/LICENSE-2.0
225
226 Unless required by applicable law or agreed to in writing, software
227 distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
228 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
229 License for the specific language governing permissions and limitations under
230 the License.
231 </pre>
Something went wrong with that request. Please try again.