-
Notifications
You must be signed in to change notification settings - Fork 2
/
presentazione.html
338 lines (285 loc) · 10.8 KB
/
presentazione.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Elastic Search</title>
<meta name="description" content="Elastic Search">
<meta name="author" content="Matteo Latini">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/default.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- If the query includes 'print-pdf', use the PDF print sheet -->
<script>
document.write( '<link rel="stylesheet" href="css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>Elastic Search</h1>
<h3></h3>
</section>
<section>
<h2>Chi sono</h2>
<p><img src="img/io.jpg" alt="Daniele Palombo" style="width:200px;"></p>
<p>Daniele Palombo -> tw: <a href="https://twitter.com/ksemuldie">@ksemuldie</a>, gh: <a href="https://github.com/danielePalombo">DanielePalombo</a></p>
<p><br></p>
<p> E-Business</p>
<p>Appassionato di sviluppo Agile e tecniche di programmazione</p>
</section>
<section data-state="alert">
<h2>Premessa</h2>
<p>ElasticSearch si ma solo in teoria</p>
<img src="img/teoria.jpg"/>
</section>
<section>
<img src="img/chi.jpg"/>
<h2>Chi è ElasticSearch?</h2>
<p><em>Distributed , RESTful, free/open source , search server</em></p>
</section>
<section>
<h2>Search Server</h2>
<p>I Search server sono dei servizi per ottimizzare l'indicizzazione di testi</p>
<ul>
<li>Sopperiscono alle mancanze delle ricerche fulltext dei database classici </li>
<li>Possono anche essere usati in alternativa a database classici</li>
<li>Ne esistono ormai tantissimi <em>Lucene</em> <em>Solr</em> <em>MSS</em></li>
<li>ElasticSearch utilizza Lucene come shard</li>
</ul>
</section>
<section>
<h2>Distributed</h2>
<p>Shard & Replica</p>
</section>
<section>
<h2>Shard</h2>
<ul>
<li>È una singola istanza di Lucene</li>
<li>Un indice è composto da più shard(default 5)</li>
<li>Gli shard possono essere distribuiti su più server</li>
</ul>
</section>
<section>
<h2>Replica</h2>
<ul>
<li>I replica sono le copie di backup del dato </li>
<li>Serve a garantire l'integrità dei dati anche in caso di disservizio di una o più macchine</li>
</ul>
</section>
<section>
<h2>RESTful</h2>
<p>ElasticSearch a differenza di altri searchengine offre un'interfaccia di accesso HTTP che sfrutta i 4 VERB del protocollo (GET , PUT , DELETE , POST) garantendo quindi un'accesso da qualsiasi linguagggio di programmazione tramite API e un semplice debugging (tramite http , curl ecc...)</p>
</section>
<section>
<h2>Opensource</h2>
<p>La scelta migliore !!!!!</p>
</section>
<section>
<h2>Installazione</h2>
<img src="img/installazione.jpg" style="width: 300px"/>
<pre><code>
cd ~
sudo apt-get update
sudo apt-get install openjdk-7-jre-headless -y
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.6.deb
sudo dpkg -i elasticsearch-0.20.6.deb
sudo service elasticsearch start
</code></pre>
</section>
<section>
<h2>Glossario</h2>
<ul>
<li><b>index</b> <em>corrisponde ai database nei db sql</em></li>
<li><b>term</b> <em>indica un termine di ricerca esatto</em></li>
<li><b>text</b> <em>indica un testo non strutturato</em></li>
<li><b>type</b> <em>può essere paragonato ad una tabella nei db relazionali</em></li>
</ul>
</section>
<section>
<h2>Client</h2>
<p>Come accennato ElasticSearch permette l'interrogazione tramite api RESTfull. <br/><br/>Potremmo utilizzare semplicemente il browser o le curl per interrogare ElasticSearch passando i dati in POST, PUT, GET o DELETE e ricevere una risposta in json o jsonp</p>
</section>
<section>
<h2>Aggiungere un elemento ad un indice</h2>
<pre><code>curl -XPUT 'http://localhost:9200/application/users/1' -d '{
"user" : "kimchy",
"status" : ""
}'
</code>
Risultato:
<code>
{"ok":true,"_index":"application","_type":"users","_id":"1","_version":1}
</code></pre>
<p></p>
</section>
<section>
<p>Il parametro version indica la versione dell'elemento , ci permette di non generare errori di concorrenza</p>
<pre><code class="bash">
curl -XPUT 'http://localhost:9200/application/users/1' -d '{
"user" : "kimchy",
"status" : ""
}'
</code>
Risultato:
<code>
{"ok":true,"_index":"application","_type":"users","_id":"1","_version":2}
</code>
Possiamo anche specificare il numero di versione
<code>
curl -XPUT 'http://localhost:9200/application/users/1?version=2' -d '{
"status" : "My status update"
}'
</code>
</pre>
</section>
<section>
<h2>DELETE</h2>
<pre><code>curl -XDELETE 'http://localhost:9200/application/users/1'
{
"ok" : true,
"_index" : "application",
"_type" : "users",
"_id" : "1",
"found" : true
}
</code></pre>
</section>
<section>
<h2>Ricerca</h2>
<pre><code>
curl -XGET 'http://localhost:9200/application/users/1'
</code>
Risultato:
<code>
{"_index":"application","_type":"users","_id":"1","_version":4,"exists":true, "_source" : {
"status" : "My status update"
}}
</code>
</pre>
</section>
<section>
<h2>Richiesta di solo alcuni campi</h2>
<pre>
<code>
curl -XGET 'http://localhost:9200/application/users/1?fields=status,name'
</code>
Risultato:
<code>
{"_index":"application","_type":"users","_id":"1","_version":5,"exists":true,"fields":{"status":"My status update","name":"my name"}}
</code>
</pre>
</section>
<section>
<h2>Percolator</h2>
<p>Il percolator è una funzionalità che permette di risalire dal termine di ricerca all'indice registrato.</p>
</section>
<section>
<h2>Registrazione</h2>
<p>Creazione di una perculator query chiamata <b>kuku</b> nell'indice <b>test</b> per il valore <b>value1</b> </p>
<pre>
<code>
curl -XPUT localhost:9200/_percolator/test/kuku -d '{
"query" : {
"term" : {
"field1" : "value1"
}
}
}'
</code>
</pre>
<p><a href="https://github.com/dylanahsmith/elasticsearch-examples/blob/master/percolate.sh">https://github.com/dylanahsmith/elasticsearch-examples/blob/master/percolate.sh</a></p>
</section>
<section>
<h2>Ricerca</h2>
<p>Inserimento di un documento che coincide con il valore di ricerca</p>
<pre><code>
curl -XGET localhost:9200/test/type1/_percolate -d '{
"doc" : {
"field1" : "value1"
}
}'
</code></pre>
</section>
<section>
<h2>Risultato</h2>
<pre><code>
{"ok":true, "matches":["kuku"]}
</code></pre>
</section>
<section>
<h2>ElasticSearch && Ruby</h2>
<p><a href="https://github.com/karmi/tire">Karmi/Tire</a></p>
</section>
<section>
<h2>Model</h2>
<pre><code class="ruby">
include Tire::Model::Search
include Tire::Model::Callbacks
def self.search(params)
tire.search(load: true) do
query { string params[:query], default_operator: "AND" } if params[:query].present?
filter :range, published_at: {lte: Time.zone.now}
end
end
</code></pre>
</section>
<section>
<h2>Search code</h2>
<pre><code class="ruby">
@result = Model.search(params)
</code></pre>
</section>
<section>
<h2>Link utili</h2>
<ul>
<li><a href="http://karmi.github.io/tire/" >http://karmi.github.io/tire/</a></li>
<li><a href="http://collectiveidea.com/blog/archives/2013/01/14/reverse-search-with-elasticsearch-1/">http://collectiveidea.com/blog/archives/2013/01/14/reverse-search-with-elasticsearch-1/</a></li>
<li><a href="http://railscasts.com/episodes/306-elasticsearch-part-1">http://railscasts.com/episodes/306-elasticsearch-part-1</a></li>
<li><a href="http://www.elasticsearch.org/guide/">http://www.elasticsearch.org/guide/</a></li>
<li><a href="https://gist.github.com/wingdspur/2026107">https://gist.github.com/wingdspur/2026107</a></li>
<li><a href="https://twitter.com/elasticsearch">https://twitter.com/elasticsearch</a></li>
<li><a href="http://stackoverflow.com/questions/15694724/shards-and-replicas-in-elasticsearch">http://stackoverflow.com/questions/15694724/shards-and-replicas-in-elasticsearch</a></li>
</ul>
</section>
<section>
<h1>THE END</h1>
<img src="img/end.jpg"/>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/fade/none
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
// { src: 'plugin/search/search.js', async: true, condition: function() { return !!document.body.classList; } }
// { src: 'plugin/remotes/remotes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>