Elasticsearch Introduction
Elasticsearch Introduction
We need it to make our lives easier Find stuff that is relevant to us Find it faster
elasticsearch
'''
Full (e%t Searching *&S(ful &S &lasticsearch in *ails +dvanced features of &S
What is elasticsearch?
Database server Implemented with RESTful HTTP/JSON Easil scalable !hence the name #ased $n %ucene
elasticsearch"
Features of elasticsearch
Sche.a/free *eal/ti.e &asy to e%tend with a plugin syste. for new functionality +uto.atic discovery of peers in a cluster Failover and replication 0o..unity support! 1ultiple clients available in various (ire ge./ ruby client available for +ctive1odel integration
(er.inology
*elational database "atabase (able *ow 0olu.n Sche.a
&lasticsearch 2nde% (ype "ocu.ent Field 1apping
2nside &S
" 0/(45&
2,"&3
+n 2nde% can have .ultiple types' " 0/(45& &ach type can have .ultiple docu.ents'
2,"&3
" 0/(45&
6''7 6''7
"ocu.ent
2,"&3
" 0/(45&
2nverted inde%ing
+nalysis
9:;
9<;
9=;
cloudy
5 S2(2 , : :>< < = = < : +re these positions in the docu.ent are consecutive ?
cloudy
5 S2(2 , : :>1 < = 2 < : We find the words in consecutive positions in "ocu.ent <
cloudy
+,+$4S2S
+naly?ing is e%tracting @ter.sA fro. given te%t' 5rocessing natural language to .ake it co.puter searchable'
*uby is a dyna.ic> reflective> general/purpose 5 language that co.bines synta% inspired by 5erl with S.alltalk/like features' *uby was first designed and developed in the .id/<BB:s by 4ukihiro C1at?C 1atsu.oto in Dapan'
ruby dyna.ic reflective general purpose oop language co.bine synta% inspire perl s.alltalk feature first design develop .id <BB: yukihiro .at? .atsu.oto japan
*uby is a dyna.ic> reflective> general/purpose 5 language that co.bines synta% inspired by 5erl with S.alltalk/like features' *uby was first designed and developed in the .id/<BB:s by 4ukihiro C1at?C 1atsu.oto in Dapan'
*uby is a dyna.ic> reflective> general/purpose 5 language that co.bines synta% inspired by 5erl with S.alltalk/like features' *uby was first designed and developed in the .id/<BB:s by 4ukihiro C1at?C 1atsu.oto in Dapan'
&S +naly?er
+naly?er! 0onsists of one tokeni?er and .ultiple token filters eg! Whitespace> Snowball>etc
(okeni?er! 2t tokeni?es all words' Splits sentences into individual Eter.sE ' ,gra. and &dge,gra. highly useful for autoco.plete feature' 5ath hierarchy tokeni?ers'
(oken filter! +ctions on tokeni?ed words> basic lowercase to phonetic filters and ste..ers Favailable in .any languagesG
5opular +naly?ers
&S is easy to use' *eady.ade analy?ers for general usage'
2ts *&S(ful
2ts *&S(ful
K&(
5 S(
58(
"&$&(&
58( /inde%/type/id
action?
58( /inde%/type/id
where?
58( /twitterLdevelop.ent/type/id
58( /twitterLdevelop.ent/type/id
what?
58( /twitterLdevelop.ent/tweet/id
58( /twitterLdevelop.ent/tweet/id
which?
58( /twitterLdevelop.ent/tweet/<
curl /358( Elocalhost!B=::/twitterLdevelop.ent/tweet/<E /d E6 CtweetC ! C &lasticsearch is cool) C> Cna.eC ! C1r "eveloperC 7E
curl /358( Elocalhost!B=::/twitterLdevelop.ent/tweet/<E /d E6 CtweetC ! C &lasticsearch is cool) C> Cna.eC ! C1r "eveloperC 7E 6 CLinde%C!CtwitterLdevelop.entC> CLtypeC!CtweetC> CLidC!C<C> CLversionC! <> CokC!true
Si.ilarly>
curl /3K&( Ehttp!//localhost!B=::/twitter/tweet/<E
Si.ilarly>
curl /3K&( Ehttp!//localhost!B=::/twitter/tweet/<E
6 CLinde%C ! CtwitterC> CLtypeC ! CtweetC> CLidC ! C<C> CLsourceC ! 6 CtweetC ! C &lasticsearch is cool) C> Cna.eC ! C1r "eveloperC 7
+lso
K&( /inde%/Lsearch K&( /inde%<>inde%=/Lsearch K&( /indM/Lsearch K&( /inde%/type/Lsearch K&( /inde%/type<>type=/Lsearch K&( /inde%/typeM/Lsearch K&( /Lall/typeM/Lsearch
Search .ultiple or all indices FdatabasesG Search all types Fcolu.nsG
Si.ilarly>
"&$&(&
"elete docu.ent
&lasticsearch in *ails
#uerying
1ore types of Nueries and use cases! Faceting ! +llowing .ultiple filters 5agination ! $i.iting per page results Sort ! Sorting results by relevance and scoring Fusing &lasticsearchEs scoring algorith.G
8S5 of &lasticsearch
,ode <
,ode =
,ode O
+<
T<
T=
T<
+=
+O
0<
+=
+O
+<
+=
T<
+O
T=
+=
T=
+<
T=
Shard
*eplica
,ode <
,ode =
,ode O
,ode P
+<
T=
0<
T=
+<
T=
+O
+=
T<
+<
High +vailability
For each inde% you can specify!
,u.ber of shards &ach inde% has fi%ed nu.ber of shards Shards i.prove inde%ing perfor.ance ,u.ber of replicas &ach shard can have :/.any replicas> can be changed dyna.ically *eplicas i.prove search perfor.ance
(ips
1ake sure you .ake separate indices for test and develop.ent environ.ent &g! +dd inde%Lna.e C0hwinkLU6*ails'env7C to your .odel file
"uring tests whenever you save an object .ake sure you add ! 0hwink'tire'inde%'refresh after each test case'
1ake sure you delete and recreate the inde% after tests' &g! 4ou can add this to your *spec configuration file config'afterF!eachG do 0hwink'tire'0hwinkLtest'delete 0hwink'tire'createLelasticsearchLinde% end "ebug using log files ! +dd to (ire config file! logger CtireLU6*ails'env7'logC
,ow you can go ahead and start e%ploring &lasticsearch for yourself))
(hank you)
#uestions are welco.e)