SlideShare a Scribd company logo
1 of 83
Elasticsearch.
                         Le moteur de recherche
                           élastique pour tous




    David Pilato, IDEO Technologies, Paris

mardi 5 février 13
Qui ?

    $ curl http://localhost:9200/talk/speaker/dpilato
    {
     "nom" : "David Pilato",
     "jobs" : [
      { "boite" : "SRA Europe (SSII)", "mission" : "bon à tout faire", "duree" : 3 },
      { "boite" : "SFR", "mission" : "touche à tout", "duree" : 3 },
      { "boite" : "e-Brands / Vivendi", "mission" : "chef de projets", "duree" : 4 },
      { "boite" : "DGDDI (douane)", "mission" : "mouton à 5 pattes", "duree" : 8 },
      { "boite" : "IDEO Technologies", "mission" : "directeur technique", "duree" : 0 } ],
     "passions" : [ "famille", "job", "deejay" ],
     "blog" : "http://dev.david.pilato.fr/",
     "twitter" : [ "@dadoonet", "@elasticsearchfr", "@scrutmydocs" ],
     "email" : "david@pilato.fr"
    }




mardi 5 février 13
ScrutMyDocs.org




mardi 5 février 13
Pour la démo


                      Faites du bruit sur Twitter
                           avec le hashtag


                     #elasticsearch

mardi 5 février 13
SQL Classique
                            Cherche moi un document
                     de décembre 2011 portant sur la france
                          et contenant produit et david
               En SQL :
                SELECT
                  doc.*, pays.*
                FROM
                  doc, pays
                WHERE
                  doc.pays_code = pays.code AND
                  doc.date_doc > to_date('2011-12', 'yyyy-mm') AND
                  doc.date_doc < to_date('2012-01', 'yyyy-mm') AND
                  lower(pays.libelle) = 'france' AND
                  lower(doc.commentaire) LIKE ‘%produit%' AND
                  lower(doc.commentaire) LIKE ‘%david%';

mardi 5 février 13
Les limites de la
                            recherche SQL
                     • Performances désastreuses sur du like
                       % sur des millions de ligne
                     • Plombe les performances de l’insertion
                     • Pas de tolérance aux fotes de frappe
                     • En général, on se limite aux champs
                       figés ou codifiés
                     • Recherche « google » impossible !

mardi 5 février 13
Au final, on obtient

                                  • Autrement dit :
                                    tu as intérêt à
                                    savoir ce que
                                    tu cherches !
                                  • Fouiller est
                                    interdit !



mardi 5 février 13
Un moteur de recherche
               • Un moteur de recherche est composé de :
                      • un moteur d’indexation de documents
                      • un moteur de recherche sur les index
               • De fait, un moteur de recherche est
                     énormément plus rapide qu’une base de
                     données pour faire des recherches :
                                c’est son métier !


mardi 5 février 13
L’indexation, c’est quoi
                            en fait ?




mardi 5 février 13
Elasticsearch
                        Your Data, your Search !




mardi 5 février 13
Elasticsearch
                     • Moteur de recherche pour la génération NoSQL
                     • Basé sur le standard Apache Lucene
                     • Masque la complexité Java/Lucene à l’aide de
                       services standards HTTP / RESTful / JSON

                     • Utilisable à partir de n’importe quelle
                       technologie

                     • Ajoute la couche cloud manquante à Lucene
                     • C’est un moteur, pas une interface graphique !


mardi 5 février 13
Points clés
                     • Simple ! En quelques minutes (Zero Conf), on dispose
                        d’un moteur complet prêt à recevoir nos documents à
                        indexer et à faire des recherches.

                     • Efficace ! Il suffit de démarrer des nœuds
                        Elasticsearch pour bénéficier immédiatement de la
                        réplication, de l’équilibrage de charge.

                     • Puissant ! Basé sur Lucene, il en parallélise les
                        traitements pour donner des temps de réponse
                        acceptables (en général inférieurs à 100ms)

                     • Complet ! Beaucoup de fonctionnalités : analyse et
                        facettes, percolation, rivières, plugins, …


mardi 5 février 13
Ranger ses données
                     • Document : Un objet représentant les données (au sens
                        NoSQL).
                        Penser "recherche", c'est oublier le SGBDR et penser
                        "Documents"
        {
          "text": "Bienvenue à la conférence #elasticsearch pour #JUG",
          "created_at": "2012-04-06T20:45:36.000Z",
          "source": "Twitter for iPad",
          "truncated": false,
          "retweet_count": 0,
          "hashtag": [ { "text": "elasticsearch", "start": 27, "end": 40 },
                       { "text": "JUG", "start": 47, "end": 55 } ],
          "user": { "id": 51172224, "name": "David Pilato",
                    "screen_name": "dadoonet", "location": "France",
                    "description": "Soft Architect, Project Manager, Senior Developper.rnAt this time, enjoying NoSQL
        world : CouchDB, ElasticSearch.rnDeeJay 4 times a year, just for fun !" }
        }


                     • Type : Regroupe des documents de même type
                     • Index : Espace logique de stockage des documents dont les
                        types sont fonctionnellement communs



mardi 5 février 13
Interagir avec
                                     Elasticsearch
                     •   API REST : http://host:port/[index]/[type]/[_action/id]
                         Méthodes HTTP : GET, POST, PUT, DELETE

                     •   Documents

                         •   curl -XPUT http://localhost:9200/twitter/tweet/1

                         •   curl -XGET http://localhost:9200/twitter/tweet/1

                         •   curl -XDELETE http://localhost:9200/twitter/tweet/1

                     •   Recherche

                         •   curl -XPOST http://localhost:9200/twitter/tweet/_search

                         •   curl -XPOST http://localhost:9200/twitter/_search

                         •   curl -XPOST http://localhost:9200/_search

                     •   Meta-données

                         •   curl -XGET http://localhost:9200/twitter/_status

                         •   curl -XPOST http://localhost:9200/_shutdown

mardi 5 février 13
Indexer
           $ curl -XPUT localhost:9200/twitter/tweet/1 -d '
           {
              "text": "Bienvenue à la conférence #elasticsearch pour #JUG",
              "created_at": "2012-04-06T20:45:36.000Z",
              "source": "Twitter for iPad",
              "truncated": false,
              "retweet_count": 0,
              "hashtag": [ { "text": "elasticsearch", "start": 27, "end": 40 },
                           { "text": "JUG", "start": 47, "end": 55 } ],
              "user": { "id": 51172224, "name": "David Pilato",
                        "screen_name": "dadoonet", "location": "France",
                        "description": "Soft Architect, Project Manager, Senior Developper.r
           nAt this time, enjoying NoSQL world : CouchDB, ElasticSearch.rnDeeJay 4 times a
           year, just for fun !" }
           }'




           {
            "ok":true,
            "_index":"twitter",
            "_type":"tweet",
            "_id":"1"
           }



mardi 5 février 13
Chercher
                 $ curl localhost:9200/twitter/tweet/_search?q=elasticsearch




             {
                 "took" : 24,                      Nb de
                 "timed_out" : false,
                                                 documents
                 "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 },
                 "hits" : {
                   "total" : 1,                                      Document
                   "max_score" : 0.227,
                   "hits" : [ {                          Coordonnées  source
                     "_index" : "twitter",
                     "_type" : "tweet",
                     "_id" : "1",
                     "_score" : 0.227, "_source" : {
                       "text": "Bienvenue à la conférence #elasticsearch pour #JUG",
                       "created_at": "2012-04-06T20:45:36.000Z",
                       "source": "Twitter for iPad",
                       […]
                     }                                Pertinence
                   } ]
                 }
             }


mardi 5 février 13
Les résultats

                     • Elasticsearch renvoie les 10 premiers
                       résultats. Il fournit l’API permettant
                       de naviguer de page en page (from,
                       size)
                     • Par défaut, le tri est réalisé sur le
                       score de pertinence



mardi 5 février 13
Query DSL
                     • Requêtes précises : plutôt que de
                       chercher « à la google », on peut
                       utiliser des critères précis :
                       $ curl -XPOST localhost:9200/twitter/tweet/_search -d ’{
                           "bool" : {
                               "must" : {
                                   "term" : { "user" : "kimchy" }
                               },
                               "must_not" : {
                                   "range" : {
                                       "age" : { "from" : 10, "to" : 20 }
                                   }
                               },
                               "should" : [
                                   {
                                       "term" : { "tag" : "wow" }
                                   },{
                                       "match" : { "tag" : "elasticsearch is cool" }
                                   }
                               ]
                           }
                       }’

mardi 5 février 13
Injecter les données
                        Et au milieu coule une rivière




mardi 5 février 13
La collecte


                 Doc
                           Stockage
                           Données




mardi 5 février 13
La collecte


                 Doc
                            Stockage
                            Données
                           Doc




mardi 5 février 13
La collecte


                          Stockage
                          Données
                         Doc   Doc




mardi 5 février 13
La collecte

                     Doc

                               Stockage
                               Données

                                 Doc



                                 Doc




mardi 5 février 13
La collecte


                         Stockage
                         Données
                           Doc




                           Doc




mardi 5 février 13
La collecte


                         Stockage
                         Données




                           Doc
                           Doc




mardi 5 février 13
Quelques Rivers...
                     •   CouchDB River

                     •   CouchBase River

                     •   MongoDB River

                     •   JDBC River

                     •   Wikipedia River

                     •   Twitter River

                     •   RabbitMQ River

                     •   ActiveMQ River

                     •   RSS River

                     •   LDAP River

                     •   FS River

                     •   Dropbox River

                     •   Dick Rivers




mardi 5 février 13
Analyser
                                   La puissance des facettes !
                     Faites parler vos données en les regardant sous différentes facettes !
                                    (Et en temps quasi réel, s’il vous plait !)




mardi 5 février 13
Des tweets

                     ID    Username          Date      Hashtag
                     1     dadoonet       2012-04-18     1
                     2        ideo        2012-04-18     5
                     3    elasticsearch   2012-04-18     2
                     4     dadoonet       2012-04-18     2
                     5        ideo        2012-04-18     6
                     6    elasticsearch   2012-04-19     3
                     7     dadoonet       2012-04-19     3
                     8        ideo        2012-04-19     7
                     9    elasticsearch   2012-04-20     4



mardi 5 février 13
Term Facet

D                 Username         Date             Hashtag
1                  dadoonet     2012-04-18            1
2                        ideo   2012-04-18            5
3             elasticsearch     2012-04-18Username 2          Count
4                  dadoonet     2012-04-18dadoonet    2        3
5                        ideo   2012-04-18   ideo     6        3
6             elasticsearch     2012-04-19
                                        elasticsearch 3        3
7                  dadoonet     2012-04-19            3
8                        ideo   2012-04-19            7
9             elasticsearch     2012-04-20            4



    mardi 5 février 13
Term Facet

D                 Username         Date             Hashtag
1                  dadoonet     2012-04-18
                                        "facets" : {    1
                                          "users" : { "terms" : {"field" : "username"} }
                                       }
2                        ideo   2012-04-18              5
                                      "facets" : {
3             elasticsearch     2012-04-18
                                        "users" : {     2
                                          "_type" : "terms",
4                  dadoonet     2012-04-18"missing" : 0,2
                                          "total": 9,
5                        ideo   2012-04-18"other": 0,   6
                                          "terms" : [
6             elasticsearch     2012-04-19 { "term" : "dadoonet", "count" },3 },
                                                        3
                                            { "term" : "ideo", "count" : 3
                                                                           :

                                            { "term" : "elasticsearch", "count" : 3 }
7                  dadoonet     2012-04-19]             3
                                        }
8                        ideo   2012-04-19
                                      }                 7
9             elasticsearch     2012-04-20              4



    mardi 5 février 13
Date Histogram Facet

                     Date   Hashtag
            2012-04-18        1                  Par mois
            2012-04-18        5          Date               Count
h           2012-04-18        2        2012-04               9
            2012-04-18        2
            2012-04-18        6                  Par jour
h           2012-04-19        3          Date               Count
            2012-04-19        3       2012-04-18             5
            2012-04-19        7       2012-04-19             3
h           2012-04-20        4       2012-04-20             1



mardi 5 février 13
Date Histogram Facet

                     Date   Hashtag
                                  "facets" : {
            2012-04-18        1     "perday" : {
                                      "date_histogram" : {
            2012-04-18        5         "field" : "date",
                                        "interval" : "day"
                                      }
h           2012-04-18        2     }
                                  }
            2012-04-18        2
                                "facets" : {
            2012-04-18        6 "perday" : {
                                    "_type" : "date_histogram",
h           2012-04-19        3     "entries": [
                                      { "time": 1334700000000, "count": 5 },
            2012-04-19        3       { "time": 1334786400000, "count": 3 },
                                      { "time": 1334872800000, "count": 1 }
            2012-04-19        7 } ]
                                }
h           2012-04-20        4



mardi 5 février 13
Range Facet

                Hashtag
                     1
                     5
                     2     Hashtag      Count   Min   Max   Moy     Total
                     2       x<3         3      1      2    1.667    5
                     6     3 <= x < 5    3      3      4    3.333    10
                     3      x >= 5       3      5      7     6       18
                     3
                     7
                     4



mardi 5 février 13
Range Facet
                             "facets" : { "hashtags" : {
                               "range" : { "field" : "hashtag",
                               "ranges" : [
                                  { "to" : 3 },
                Hashtag           { "from" : 3, "to" : 5 },
                                  { "from" : 5 }
                               ] } } }
                     1
                           "facets" : {
                     5       "hashtags" : {
                               "_type" : "range",
                     2         "ranges" : [ {
                                   "to": 3,
                     2             "count": 3,
                                   "min": 1, "max": 2,
                     6             "total": 5, "mean": 1.667
                                 }, {
                                   "from":3, "to" : 5,
                     3             "count": 3,
                                   "min": 3, "max": 4,
                     3             "total": 10, "mean": 3.333
                                 },{
                     7             "from":5,
                                   "count": 3,
                     4             "min": 5, "max": 7,
                                   "total": 18, "mean": 6
                                 } ] } }



mardi 5 février 13
Site marchand

                           Ranges




                           Term




                           Term




                          Ranges
mardi 5 février 13
Analyse temps-réel
                     • Faire un matchAll sur l'ensemble des données
                     • Actualiser toutes les x secondes
                     • Indexer en même temps les nouvelles données

                                                             Date histogram



                                                             Term




mardi 5 février 13
Facettes
                     Cartographiques




mardi 5 février 13
Reprenons notre
                       formulaire

                                Recherche Full Text




mardi 5 février 13
Reprenons notre
                       formulaire




mardi 5 février 13
Démonstration
                     Avez-vous fait du bruit ?




mardi 5 février 13
Architecture

             Chrome
                                                         Twitter
                                         Twitter        Streaming
                                          River            API




                     $ curl -XPUT localhost:9200/_river/twitter/_meta -d '
                     {
                        "type" : "twitter",
                        "twitter" : {
                          "user" : "twitter_user",
                          "password" : "twitter_password",
                          "filter" : { "tracks" : ["elasticsearch"] }
                        }
                     }'

mardi 5 février 13
Démonstration
                     http://onemilliontweetmap.com/




mardi 5 février 13
Architecture
                     Un peu plus de technique : partitions / réplications / scalabilité




mardi 5 février 13
Lexique
                     • Nœud (node) : Une instance d'Elasticsearch (~ machine ?)
                     • Cluster : Un ensemble de nœuds
                     • Partition (shard) : permet de découper un index en plusieurs
                        parties pour y distribuer les documents

                     • Réplication (replica) : recopie d’une partition en une ou
                        plusieurs copies dans l'ensemble du cluster

                     • Partition primaire (primary shard) : partition élue
                        "principale" dans l'ensemble du cluster. C'est là que se fait
                        l'indexation par Lucene. Il n'y en a qu'une seule par shard dans
                        l'ensemble du cluster.

                     • Partition secondaire (secondary shard) : partitions
                        secondaires stockant les replicas des partitions primaires.



mardi 5 février 13
Créons un index


             $ curl -XPUT localhost:9200/twitter -d '{                                     Cluster
                     "index" : {
                                                                                Nœud 1
                                                                                Nœud 1               Nœud 2
                         "number_of_shards" : 2,
                         "number_of_replicas" : 1                               Shard 00
                                                                                 Shard               Shard 0
                     }
                                                                                Shard 11
                                                                                 Shard
             }'                                                                                      Shard 1




                                                    réplication non respectée
                                                      réplication respectée
                                                                                            Client
                                                                                            CURL




mardi 5 février 13
Réallocation dynamique


                                            Cluster

                        Nœud 1    Nœud 2              Nœud 3
                        Shard 0   Shard 0


                        Shard 1   Shard 1




mardi 5 février 13
Réallocation dynamique


                                            Cluster

                        Nœud 1    Nœud 2              Nœud 3
                        Shard 0   Shard 0              Shard 0


                        Shard 1   Shard 1




mardi 5 février 13
Réallocation dynamique


                                            Cluster

                        Nœud 1    Nœud 2              Nœud 3     Nœud 4
                        Shard 0                        Shard 0


                        Shard 1   Shard 1




mardi 5 février 13
Réallocation dynamique


                                                Cluster

                            Nœud 1    Nœud 2              Nœud 3     Nœud 4
                            Shard 0                        Shard 0


                            Shard 1   Shard 1                        Shard 1




                      Le tuning, c'est trouver le bon équilibre entre le
                         nombre de nodes, shards et replicas !



mardi 5 février 13
Indexons un document

                                                            Cluster

                        Nœud 1                Nœud 2                     Nœud 3               Nœud 4
                        Shard 0                                           Shard 0


                                              Shard 1                                          Shard 1




                                  Doc
                                   1 Client         $ curl -XPUT localhost:9200/twitter/tweet/1 -d '
                                     CURL           {
                                                         "text": "Bienvenue à la conférence #elasticsearch pour #JUG",
                                                         "created_at": "2012-04-06T20:45:36.000Z",
                                                         "source": "Twitter for iPad",
                                                         ...
                                                    }'




mardi 5 février 13
Indexons un document

                                                               Cluster

                        Nœud 1                   Nœud 2                     Nœud 3               Nœud 4
                                  Doc
                        Shard 0    1                                         Shard 0


                                                 Shard 1                                          Shard 1




                                        Client         $ curl -XPUT localhost:9200/twitter/tweet/1 -d '
                                        CURL           {
                                                            "text": "Bienvenue à la conférence #elasticsearch pour #JUG",
                                                            "created_at": "2012-04-06T20:45:36.000Z",
                                                            "source": "Twitter for iPad",
                                                            ...
                                                       }'




mardi 5 février 13
Indexons un document

                                                               Cluster

                        Nœud 1                   Nœud 2                     Nœud 3               Nœud 4
                                  Doc                                                  Doc
                        Shard 0    1                                         Shard 0    1


                                                 Shard 1                                          Shard 1




                                        Client         $ curl -XPUT localhost:9200/twitter/tweet/1 -d '
                                        CURL           {
                                                            "text": "Bienvenue à la conférence #elasticsearch pour #JUG",
                                                            "created_at": "2012-04-06T20:45:36.000Z",
                                                            "source": "Twitter for iPad",
                                                            ...
                                                       }'




mardi 5 février 13
Indexons un                                                           2ème

                        document
                                                             Cluster

                     Nœud 1                    Nœud 2                     Nœud 3               Nœud 4
                                Doc                                                  Doc
                      Shard 0    1                                         Shard 0    1


                                               Shard 1                                          Shard 1




                                Doc
                                 2
                                      Client         $ curl -XPUT localhost:9200/twitter/tweet/2 -d '
                                      CURL           {
                                                          "text": "Je fais du bruit pour #elasticsearch à #JUG",
                                                          "created_at": "2012-04-06T21:12:52.000Z",
                                                          "source": "Twitter for iPad",
                                                          ...
                                                     }'




mardi 5 février 13
Indexons un                                                           2ème

                        document
                                                             Cluster

                     Nœud 1                    Nœud 2                     Nœud 3               Nœud 4
                                Doc                                                  Doc
                      Shard 0    1                                         Shard 0    1


                                               Shard 1                                          Shard 1
                        Doc
                         2




                                      Client         $ curl -XPUT localhost:9200/twitter/tweet/2 -d '
                                      CURL           {
                                                          "text": "Je fais du bruit pour #elasticsearch à #JUG",
                                                          "created_at": "2012-04-06T21:12:52.000Z",
                                                          "source": "Twitter for iPad",
                                                          ...
                                                     }'




mardi 5 février 13
Indexons un                                                           2ème

                        document
                                                             Cluster

                     Nœud 1                    Nœud 2                     Nœud 3               Nœud 4
                                Doc                                                  Doc
                      Shard 0    1                                         Shard 0    1


                                               Shard 1    Doc                                   Shard 1
                                                           2




                                      Client         $ curl -XPUT localhost:9200/twitter/tweet/2 -d '
                                      CURL           {
                                                          "text": "Je fais du bruit pour #elasticsearch à #JUG",
                                                          "created_at": "2012-04-06T21:12:52.000Z",
                                                          "source": "Twitter for iPad",
                                                          ...
                                                     }'




mardi 5 février 13
Indexons un                                                           2ème

                        document
                                                             Cluster

                     Nœud 1                    Nœud 2                     Nœud 3               Nœud 4
                                Doc                                                  Doc
                      Shard 0    1                                         Shard 0    1


                                                          Doc                                             Doc
                                               Shard 1                                          Shard 1
                                                           2                                               2




                                      Client         $ curl -XPUT localhost:9200/twitter/tweet/2 -d '
                                      CURL           {
                                                          "text": "Je fais du bruit pour #elasticsearch à #JUG",
                                                          "created_at": "2012-04-06T21:12:52.000Z",
                                                          "source": "Twitter for iPad",
                                                          ...
                                                     }'




mardi 5 février 13
Cherchons !

                                                          Cluster

                     Nœud 1                   Nœud 2                Nœud 3          Nœud 4
                               Doc                                            Doc
                     Shard 0    1                                   Shard 0    1


                                                        Doc                                   Doc
                                              Shard 1                               Shard 1
                                                         2                                     2




                                     Client
                                              $ curl localhost:9200/twitter/_search?q=elasticsearch
                                     CURL




mardi 5 février 13
Cherchons !

                                                    Cluster

                     Nœud 1               Nœud 2              Nœud 3          Nœud 4
                                                                        Doc
                      Shard 0                                 Shard 0    1


                                                                                        Doc
                                          Shard 1                             Shard 1
                     Doc                                                                 2
                           Doc
                      1     2




                                 Client
                                          $ curl localhost:9200/twitter/_search?q=elasticsearch
                                 CURL




mardi 5 février 13
Cherchons !

                                              {
                                                          Cluster
                                                  "took" : 24,
                     Nœud 1                    "timed_out" : false,Nœud 3
                                              Nœud 2                                  Nœud 4
                                                "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 },
                                                                               Doc
                     Shard 0                    "hits" : {             Shard 0 1
                                                   "total" : 2,
                                                   "max_score" : 0.227,                          Doc
                                               Shard 1
                                                   "hits" : [ {                          Shard 1
                                                                                                  2
                                                      "_index" : "twitter",
                                                      "_type" : "tweet",
                                                      "_id" : "1",
                                                      "_score" : 0.227, "_source" : { ... }
                                       Doc         }, {
                               Doc      2             "_index" : "twitter",
                                1
                                     Client           "_type" : "tweet",
                                              $ curl localhost:9200/twitter/_search?q=elasticsearch
                                     CURL             "_id" : "2",
                                                      "_score" : 0.152, "_source" : { ... }
                                                   } ]
                                                }




mardi 5 février 13
Cherchons encore !

                                                            Cluster

                       Nœud 1                   Nœud 2                Nœud 3          Nœud 4
                                 Doc                                            Doc
                       Shard 0    1                                   Shard 0    1


                                                          Doc                                   Doc
                                                Shard 1                               Shard 1
                                                           2                                     2




                                       Client
                                                $ curl localhost:9200/twitter/_search?q=elasticsearch
                                       CURL




mardi 5 février 13
Cherchons encore !

                                                            Cluster

                       Nœud 1                   Nœud 2                Nœud 3       Nœud 4
                                 Doc
                       Shard 0    1                                   Shard 0
                                                  Doc
                                                   1
                                                Shard 1   Doc         Doc           Shard 1
                                                           2           2




                                       Client
                                                $ curl localhost:9200/twitter/_search?q=elasticsearch
                                       CURL




mardi 5 février 13
Cherchons encore !

                                                          Cluster

                       Nœud 1                   Nœud 2              Nœud 3
                                 Doc
                       Shard 0    1                                 Shard 0


                                                Shard 1
                        Doc      Doc
                         1        2




                                       Client
                                                $ curl localhost:9200/twitter/_search?q=elasticsearch
                                       CURL




mardi 5 février 13
Cherchons encore !

                                              {
                                                          Cluster
                                                  "took" : 24,
                       Nœud 1                  "timed_out" : false,Nœud 3
                                              Nœud 2
                                                "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 },
                                 Doc
                       Shard 0    1             "hits" : {             Shard 0
                                                   "total" : 2,
                                                   "max_score" : 0.227,
                                               Shard 1
                                                   "hits" : [ {
                                                      "_index" : "twitter",
                                                      "_type" : "tweet",
                                                      "_id" : "1",
                                                      "_score" : 0.227, "_source" : { ... }
                                        Doc        }, {
                                         2
                                 Doc                  "_index" : "twitter",
                                  1 Client
                                                      "_type" : "tweet",
                                              $ curl localhost:9200/twitter/_search?q=elasticsearch
                                       CURL           "_id" : "2",
                                                      "_score" : 0.152, "_source" : { ... }
                                                   } ]
                                                }




mardi 5 février 13
La percolation
                        Ou la recherche inversée




mardi 5 février 13
Usage courant d’un
                       moteur de recherche

                     • J’indexe un document
                     • Je cherche de temps en temps si un
                       document m’intéresse

                     • Avec de la chance, il sera bien placé au
                       niveau pertinence dans les résultats.
                       Sinon, il passe inaperçu !



mardi 5 février 13
La recherche inversée

                     • Enregistrer ses critères de recherche
                     • A chaque document indexé, on
                       récupère la liste des recherches qui
                       correspondent
                     • On a un « listener » sur le moteur
                       d’indexation : le percolator



mardi 5 février 13
Usage du percolator
                $ curl -XPOST localhost:9200/_percolator/twitter/dadoonet -d ’{
                    "query" : { "term" : { "user.screen_name" : "dadoonet" } }
                }’

                $ curl -XPOST localhost:9200/_percolator/twitter/elasticsearch -d ’{
                    "query" : { "match" : { "hashtag.text" : "elasticsearch" } }
                }’

                $ curl -XPOST localhost:9200/_percolator/twitter/mycomplexquery -d ’{
                    "query" : {
                        "bool" : {
                            "must" : {
                                "term" : { "user" : "kimchy" }
                            },
                            "must_not" : {
                                "range" : {
                                    "age" : { "from" : 10, "to" : 20 }
                                }
                            },
                            "should" : [
                                {
                                    "term" : { "tag" : "wow" }
                                },{
                                    "match" : { "tag" : "elasticsearch is cool" }
                                }
                            ]
                        }
                    }
                }’

mardi 5 février 13
Usage du percolator
                $ curl -XPUT localhost:9200/twitter/tweet/1&percolate=* -d '{
                   "text": "Bienvenue à la conférence #elasticsearch pour #JUG",
                   "created_at": "2012-04-06T20:45:36.000Z",
                   "source": "Twitter for iPad",
                   "truncated": false,
                   "retweet_count": 0,
                   "hashtag": [ { "text": "elasticsearch", "start": 27, "end": 40 },
                                { "text": "JUG", "start": 47, "end": 55 } ],
                   "user": { "id": 51172224, "name": "David Pilato",
                             "screen_name": "dadoonet", "location": "France",
                             "description": "Soft Architect, Project Manager, Senior
                Developper.rnAt this time, enjoying NoSQL world : CouchDB, ElasticSearch.r
                nDeeJay 4 times a year, just for fun !" }
                }'




                {
                     "ok": true,
                     "_index": "twitter",
                     "_type": "tweet",
                     "_id": "1",
                     "matches": [
                       "dadoonet",
                       "elasticsearch"
                     ]
                }

mardi 5 février 13
Tout doit être
                       indexé ?
                        Analyse et mapping




mardi 5 février 13
The lazy dog...

                       The quick brown fox
                     jumped over the lazy Dog

                       The quick brown fox
                     jumped over the lazy dog

mardi 5 février 13
Analyseur standard
                $ curl -XPOST 'localhost:9200/test/_analyze?analyzer=standard&pretty=1' -d
                'The quick brown fox jumped over the lazy Dog'




                {
                     "tokens" : [ {
                       "token" : "quick",
                       "start_offset": 4, "end_offset": 9, "type": "<ALPHANUM>", "position": 2
                     }, {
                       "token" : "brown",
                       "start_offset": 10, "end_offset": 15, "type": "<ALPHANUM>", "position":   3
                     }, {
                       "token" : "fox",
                       "start_offset": 16, "end_offset": 19, "type": "<ALPHANUM>", "position":   4
                     }, {
                       "token": "jumped",
                       "start_offset": 20, "end_offset": 26, "type": "<ALPHANUM>", "position":   5
                     }, {
                       "token": "over",
                       "start_offset": 27, "end_offset": 31, "type": "<ALPHANUM>", "position":   6
                     }, {
                       "token" : "lazy",
                       "start_offset": 36, "end_offset": 40, "type": "<ALPHANUM>", "position":   8
                     }, {
                       "token" : "dog",
                       "start_offset": 41, "end_offset": 44, "type": "<ALPHANUM>", "position":   9
                     } ] }
mardi 5 février 13
Analyseur whitespace
                $ curl -XPOST 'localhost:9200/test/_analyze?analyzer=whitespace&pretty=1' -d
                'The quick brown fox jumped over the lazy Dog'




                {
                     "tokens" : [ {
                       "token" : "The", ...
                     }, {
                       "token" : "quick", ...
                     }, {
                       "token" : "brown", ...
                     }, {
                       "token" : "fox", ...
                     }, {
                       "token" : "jumped", ...
                     }, {
                       "token" : "over", ...
                     }, {
                       "token" : "the", ...
                     }, {
                       "token" : "lazy", ...
                     }, {
                       "token" : "Dog", ...
                     } ] }



mardi 5 février 13
Un analyseur


                      Un ensemble
                     de tokenizers et
                        de filtres


mardi 5 février 13
Un tokenizer

               • Découpe une chaine en « mots » et
                     transforme :
               • whitespace tokenizer :
                            "the dog!" -> "the", "dog!"
               • standard tokenizer :
                             "the dog!" -> "the", "dog"


mardi 5 février 13
Un filtre
               • Supprime ou transforme un token :
                     • asciifolding filter :
                                              éléphant -> elephant
                     • stemmer filter (french) :
                                              elephants -> "eleph"
                                               cheval -> "cheval"
                                              chevaux -> "cheval"
                     • phonetic (plugin) :
                                                quick -> "Q200"
                                                 quik -> "Q200"



mardi 5 février 13
Analyzer

    "analysis":{
        "analyzer":{
         "francais":{
          "type":"custom",
          "tokenizer":"standard",
          "filter":["lowercase", "stop_francais", "fr_stemmer", "asciifolding", "elision"]
         }
        },
        "filter":{
         "stop_francais":{
          "type":"stop",
          "stopwords":["_french_", "twitter"]
         },
         "fr_stemmer" : {
          "type" : "stemmer",
          "name" : "french"
         },
         "elision" : {
          "type" : "elision",
          "articles" : ["l", "m", "t", "qu", "n", "s", "j", "d"]
         }
        }
       }



mardi 5 février 13
Mapping
             "type1" : {
                 "properties" : {
                     "text1" : { "type" : "string", "analyzer" : "simple" },
                     "text2" : { "type" : "string", "index_analyzer" : "simple",
                                                     "search_analyzer" : "standard"
                     },
                     "text3" : {
                         "type" : "multi_field",
                         "fields" : {
                             "text3" : {
                                  "type" : "string",
                                  "analyzer" : "standard"
                             },
                             "ngram" : {
                                  "type" : "string",
                                  "analyzer" : "ngram"
                             },
                             "soundex" : {
                                  "type" : "string",
                                  "analyzer" : "soundex"
                             }
                         }
                     }
                 }
             }


mardi 5 février 13
Les types
                     • string               • multi_field
                     • integer / long       • ip
                     • float / double        • geo_point
                     • boolean              • geo_shape
                     • null                 • binary
                     • array                • attachment (plugin)
                     • objects


mardi 5 février 13
Champs spéciaux

                     • _all (et include_in_all)
                     • _source
                     • _ttl
                     • parent / child
                     • nested


mardi 5 février 13
Autres fonctionnalités
                     • highlighting
                     • scoring
                     • sort
                     • explain
                     • multi get / multi search
                     • bulk

mardi 5 février 13
Démonstrations
                      www.scrutmydocs.org
                       CURL est ton ami !
                     JAVA est aussi ton ami !




mardi 5 février 13
La communauté




                     ~100 contributeurs directs au projet (+ de 2800 watchers et + de 470 forks)
mardi 5 février 13
Rejoignez le mouvement !
                       @ElasticsearchFR
                                                                        www.elasticsearch.fr




                                                                   ss
                                                                   re
                                                                  og
                                                              pr
                                                             in




                     Questions ?
                      Posez aussi vos questions sur elasticsearch-fr@googlegroups.com


              Slides sur http://fr.slideshare.net/dadoonet               Sources sur https://github.com/dadoonet/talks
mardi 5 février 13

More Related Content

What's hot

Lausanne JUG - Elasticsearch
Lausanne JUG - ElasticsearchLausanne JUG - Elasticsearch
Lausanne JUG - ElasticsearchDavid Pilato
 
Elasticsearch - Esme sudria
Elasticsearch - Esme sudriaElasticsearch - Esme sudria
Elasticsearch - Esme sudriaDavid Pilato
 
Paris data geek - Elasticsearch
Paris data geek - ElasticsearchParis data geek - Elasticsearch
Paris data geek - ElasticsearchDavid Pilato
 
Hands on lab Elasticsearch
Hands on lab ElasticsearchHands on lab Elasticsearch
Hands on lab ElasticsearchDavid Pilato
 
A la recherche d'ElasticSearch
A la recherche d'ElasticSearchA la recherche d'ElasticSearch
A la recherche d'ElasticSearchNinnir
 
Besoin de rien Envie de Search - Presentation Lucene Solr ElasticSearch
Besoin de rien Envie de Search - Presentation Lucene Solr ElasticSearchBesoin de rien Envie de Search - Presentation Lucene Solr ElasticSearch
Besoin de rien Envie de Search - Presentation Lucene Solr ElasticSearchfrancelabs
 
Breizhcamp 2015 - Comment (ne pas réussir à) modéliser ses data dans elastics...
Breizhcamp 2015 - Comment (ne pas réussir à) modéliser ses data dans elastics...Breizhcamp 2015 - Comment (ne pas réussir à) modéliser ses data dans elastics...
Breizhcamp 2015 - Comment (ne pas réussir à) modéliser ses data dans elastics...Bruno Bonnin
 
Solr and Elasticsearch in Action (at Breizhcamp)
Solr and Elasticsearch in Action (at Breizhcamp)Solr and Elasticsearch in Action (at Breizhcamp)
Solr and Elasticsearch in Action (at Breizhcamp)Lucian Precup
 
Lyon JUG - Elasticsearch
Lyon JUG - ElasticsearchLyon JUG - Elasticsearch
Lyon JUG - ElasticsearchDavid Pilato
 
[Breizhcamp 2015] MongoDB et Elastic, meilleurs ennemis ?
[Breizhcamp 2015] MongoDB et Elastic, meilleurs ennemis ?[Breizhcamp 2015] MongoDB et Elastic, meilleurs ennemis ?
[Breizhcamp 2015] MongoDB et Elastic, meilleurs ennemis ?Sébastien Prunier
 
Tirer le meilleur de ses données avec ElasticSearch
Tirer le meilleur de ses données avec ElasticSearchTirer le meilleur de ses données avec ElasticSearch
Tirer le meilleur de ses données avec ElasticSearchSéven Le Mesle
 
Elasticsearch - OSDC France 2012
Elasticsearch - OSDC France 2012Elasticsearch - OSDC France 2012
Elasticsearch - OSDC France 2012David Pilato
 
Solr + Hadoop - Fouillez facilement dans votre système Big Data
Solr + Hadoop - Fouillez facilement dans votre système Big DataSolr + Hadoop - Fouillez facilement dans votre système Big Data
Solr + Hadoop - Fouillez facilement dans votre système Big Datafrancelabs
 
Oxalide Workshop #3 - Elasticearch, an overview
Oxalide Workshop #3 - Elasticearch, an overviewOxalide Workshop #3 - Elasticearch, an overview
Oxalide Workshop #3 - Elasticearch, an overviewLudovic Piot
 
Atelier : Développement rapide d&rsquo;une application basée surXWiki
Atelier : Développement rapide d&rsquo;une application basée surXWikiAtelier : Développement rapide d&rsquo;une application basée surXWiki
Atelier : Développement rapide d&rsquo;une application basée surXWikiKorteby Farouk
 
MongoDB et Elasticsearch, meilleurs ennemis ?
MongoDB et Elasticsearch, meilleurs ennemis ?MongoDB et Elasticsearch, meilleurs ennemis ?
MongoDB et Elasticsearch, meilleurs ennemis ?Sébastien Prunier
 
Webinaire 3 de la série « Retour aux fondamentaux » : Conception de schémas :...
Webinaire 3 de la série « Retour aux fondamentaux » : Conception de schémas :...Webinaire 3 de la série « Retour aux fondamentaux » : Conception de schémas :...
Webinaire 3 de la série « Retour aux fondamentaux » : Conception de schémas :...MongoDB
 
Tout ce que le getting started mongo db ne vous dira pas
Tout ce que le getting started mongo db ne vous dira pasTout ce que le getting started mongo db ne vous dira pas
Tout ce que le getting started mongo db ne vous dira pasPierre-Alban DEWITTE
 
Hadoop et son écosystème - v2
Hadoop et son écosystème - v2Hadoop et son écosystème - v2
Hadoop et son écosystème - v2Khanh Maudoux
 
MongoDB : la base NoSQL qui réinvente la gestion de données
MongoDB : la base NoSQL qui réinvente la gestion de donnéesMongoDB : la base NoSQL qui réinvente la gestion de données
MongoDB : la base NoSQL qui réinvente la gestion de donnéesSOAT
 

What's hot (20)

Lausanne JUG - Elasticsearch
Lausanne JUG - ElasticsearchLausanne JUG - Elasticsearch
Lausanne JUG - Elasticsearch
 
Elasticsearch - Esme sudria
Elasticsearch - Esme sudriaElasticsearch - Esme sudria
Elasticsearch - Esme sudria
 
Paris data geek - Elasticsearch
Paris data geek - ElasticsearchParis data geek - Elasticsearch
Paris data geek - Elasticsearch
 
Hands on lab Elasticsearch
Hands on lab ElasticsearchHands on lab Elasticsearch
Hands on lab Elasticsearch
 
A la recherche d'ElasticSearch
A la recherche d'ElasticSearchA la recherche d'ElasticSearch
A la recherche d'ElasticSearch
 
Besoin de rien Envie de Search - Presentation Lucene Solr ElasticSearch
Besoin de rien Envie de Search - Presentation Lucene Solr ElasticSearchBesoin de rien Envie de Search - Presentation Lucene Solr ElasticSearch
Besoin de rien Envie de Search - Presentation Lucene Solr ElasticSearch
 
Breizhcamp 2015 - Comment (ne pas réussir à) modéliser ses data dans elastics...
Breizhcamp 2015 - Comment (ne pas réussir à) modéliser ses data dans elastics...Breizhcamp 2015 - Comment (ne pas réussir à) modéliser ses data dans elastics...
Breizhcamp 2015 - Comment (ne pas réussir à) modéliser ses data dans elastics...
 
Solr and Elasticsearch in Action (at Breizhcamp)
Solr and Elasticsearch in Action (at Breizhcamp)Solr and Elasticsearch in Action (at Breizhcamp)
Solr and Elasticsearch in Action (at Breizhcamp)
 
Lyon JUG - Elasticsearch
Lyon JUG - ElasticsearchLyon JUG - Elasticsearch
Lyon JUG - Elasticsearch
 
[Breizhcamp 2015] MongoDB et Elastic, meilleurs ennemis ?
[Breizhcamp 2015] MongoDB et Elastic, meilleurs ennemis ?[Breizhcamp 2015] MongoDB et Elastic, meilleurs ennemis ?
[Breizhcamp 2015] MongoDB et Elastic, meilleurs ennemis ?
 
Tirer le meilleur de ses données avec ElasticSearch
Tirer le meilleur de ses données avec ElasticSearchTirer le meilleur de ses données avec ElasticSearch
Tirer le meilleur de ses données avec ElasticSearch
 
Elasticsearch - OSDC France 2012
Elasticsearch - OSDC France 2012Elasticsearch - OSDC France 2012
Elasticsearch - OSDC France 2012
 
Solr + Hadoop - Fouillez facilement dans votre système Big Data
Solr + Hadoop - Fouillez facilement dans votre système Big DataSolr + Hadoop - Fouillez facilement dans votre système Big Data
Solr + Hadoop - Fouillez facilement dans votre système Big Data
 
Oxalide Workshop #3 - Elasticearch, an overview
Oxalide Workshop #3 - Elasticearch, an overviewOxalide Workshop #3 - Elasticearch, an overview
Oxalide Workshop #3 - Elasticearch, an overview
 
Atelier : Développement rapide d&rsquo;une application basée surXWiki
Atelier : Développement rapide d&rsquo;une application basée surXWikiAtelier : Développement rapide d&rsquo;une application basée surXWiki
Atelier : Développement rapide d&rsquo;une application basée surXWiki
 
MongoDB et Elasticsearch, meilleurs ennemis ?
MongoDB et Elasticsearch, meilleurs ennemis ?MongoDB et Elasticsearch, meilleurs ennemis ?
MongoDB et Elasticsearch, meilleurs ennemis ?
 
Webinaire 3 de la série « Retour aux fondamentaux » : Conception de schémas :...
Webinaire 3 de la série « Retour aux fondamentaux » : Conception de schémas :...Webinaire 3 de la série « Retour aux fondamentaux » : Conception de schémas :...
Webinaire 3 de la série « Retour aux fondamentaux » : Conception de schémas :...
 
Tout ce que le getting started mongo db ne vous dira pas
Tout ce que le getting started mongo db ne vous dira pasTout ce que le getting started mongo db ne vous dira pas
Tout ce que le getting started mongo db ne vous dira pas
 
Hadoop et son écosystème - v2
Hadoop et son écosystème - v2Hadoop et son écosystème - v2
Hadoop et son écosystème - v2
 
MongoDB : la base NoSQL qui réinvente la gestion de données
MongoDB : la base NoSQL qui réinvente la gestion de donnéesMongoDB : la base NoSQL qui réinvente la gestion de données
MongoDB : la base NoSQL qui réinvente la gestion de données
 

Viewers also liked

Elasticsearch in 15 minutes
Elasticsearch in 15 minutesElasticsearch in 15 minutes
Elasticsearch in 15 minutesDavid Pilato
 
ElasticSearch : Architecture et Développement
ElasticSearch : Architecture et DéveloppementElasticSearch : Architecture et Développement
ElasticSearch : Architecture et DéveloppementMohamed hedi Abidi
 
Moteurs de recherche et Lucene at LorraineJUG
Moteurs de recherche et Lucene at LorraineJUGMoteurs de recherche et Lucene at LorraineJUG
Moteurs de recherche et Lucene at LorraineJUGLucian Precup
 
Introduction to elasticsearch
Introduction to elasticsearchIntroduction to elasticsearch
Introduction to elasticsearchpmanvi
 
Apache solr andré bois-crettez 08
Apache solr   andré bois-crettez 08Apache solr   andré bois-crettez 08
Apache solr andré bois-crettez 08Loïc Descotte
 
Simple fuzzy Name Matching in Elasticsearch - Graham Morehead
Simple fuzzy Name Matching in Elasticsearch - Graham MoreheadSimple fuzzy Name Matching in Elasticsearch - Graham Morehead
Simple fuzzy Name Matching in Elasticsearch - Graham MoreheadBasis Technology
 
Elasticsearch presentation 1
Elasticsearch presentation 1Elasticsearch presentation 1
Elasticsearch presentation 1Maruf Hassan
 
Chapitre2 prise en_main_kibana
Chapitre2 prise en_main_kibanaChapitre2 prise en_main_kibana
Chapitre2 prise en_main_kibanaFabien SABATIER
 
Chapitre3 elk concepts_avances
Chapitre3 elk concepts_avancesChapitre3 elk concepts_avances
Chapitre3 elk concepts_avancesFabien SABATIER
 
Introduction to Elasticsearch with basics of Lucene
Introduction to Elasticsearch with basics of LuceneIntroduction to Elasticsearch with basics of Lucene
Introduction to Elasticsearch with basics of LuceneRahul Jain
 
Fonds verts 2012_novethic
Fonds verts 2012_novethicFonds verts 2012_novethic
Fonds verts 2012_novethicPhilippe Porta
 
Miña terra galega –Siniestro Total (Tópicos galegos) Antropoloxía 1ºBac
Miña terra galega –Siniestro Total (Tópicos galegos) Antropoloxía 1ºBacMiña terra galega –Siniestro Total (Tópicos galegos) Antropoloxía 1ºBac
Miña terra galega –Siniestro Total (Tópicos galegos) Antropoloxía 1ºBacsraqwerty
 
Acuñación de las monedas en panamá
Acuñación de las monedas en panamáAcuñación de las monedas en panamá
Acuñación de las monedas en panamámitzuriz montenegro
 
Tejido muscular y nervioso 1ºBac A
Tejido muscular y nervioso 1ºBac ATejido muscular y nervioso 1ºBac A
Tejido muscular y nervioso 1ºBac Asraqwerty
 
Literate Environment
Literate EnvironmentLiterate Environment
Literate Environmentgonzalez07
 
Forma tradicional para el registro almacenamiento
Forma tradicional para el registro almacenamientoForma tradicional para el registro almacenamiento
Forma tradicional para el registro almacenamientoElamigojiumber
 
Obra publica
Obra publicaObra publica
Obra publicaaldojbm
 
Riesgos de navegar en internet
Riesgos de navegar en internetRiesgos de navegar en internet
Riesgos de navegar en internetSpericueta
 

Viewers also liked (20)

Elasticsearch in 15 minutes
Elasticsearch in 15 minutesElasticsearch in 15 minutes
Elasticsearch in 15 minutes
 
ElasticSearch : Architecture et Développement
ElasticSearch : Architecture et DéveloppementElasticSearch : Architecture et Développement
ElasticSearch : Architecture et Développement
 
Moteurs de recherche et Lucene at LorraineJUG
Moteurs de recherche et Lucene at LorraineJUGMoteurs de recherche et Lucene at LorraineJUG
Moteurs de recherche et Lucene at LorraineJUG
 
Introduction to elasticsearch
Introduction to elasticsearchIntroduction to elasticsearch
Introduction to elasticsearch
 
Apache solr andré bois-crettez 08
Apache solr   andré bois-crettez 08Apache solr   andré bois-crettez 08
Apache solr andré bois-crettez 08
 
Simple fuzzy Name Matching in Elasticsearch - Graham Morehead
Simple fuzzy Name Matching in Elasticsearch - Graham MoreheadSimple fuzzy Name Matching in Elasticsearch - Graham Morehead
Simple fuzzy Name Matching in Elasticsearch - Graham Morehead
 
Chapitre1 elk chez_psa
Chapitre1 elk chez_psaChapitre1 elk chez_psa
Chapitre1 elk chez_psa
 
Elasticsearch presentation 1
Elasticsearch presentation 1Elasticsearch presentation 1
Elasticsearch presentation 1
 
Chapitre2 prise en_main_kibana
Chapitre2 prise en_main_kibanaChapitre2 prise en_main_kibana
Chapitre2 prise en_main_kibana
 
Chapitre3 elk concepts_avances
Chapitre3 elk concepts_avancesChapitre3 elk concepts_avances
Chapitre3 elk concepts_avances
 
Introduction to Elasticsearch with basics of Lucene
Introduction to Elasticsearch with basics of LuceneIntroduction to Elasticsearch with basics of Lucene
Introduction to Elasticsearch with basics of Lucene
 
Fonds verts 2012_novethic
Fonds verts 2012_novethicFonds verts 2012_novethic
Fonds verts 2012_novethic
 
Miña terra galega –Siniestro Total (Tópicos galegos) Antropoloxía 1ºBac
Miña terra galega –Siniestro Total (Tópicos galegos) Antropoloxía 1ºBacMiña terra galega –Siniestro Total (Tópicos galegos) Antropoloxía 1ºBac
Miña terra galega –Siniestro Total (Tópicos galegos) Antropoloxía 1ºBac
 
Acuñación de las monedas en panamá
Acuñación de las monedas en panamáAcuñación de las monedas en panamá
Acuñación de las monedas en panamá
 
Tejido muscular y nervioso 1ºBac A
Tejido muscular y nervioso 1ºBac ATejido muscular y nervioso 1ºBac A
Tejido muscular y nervioso 1ºBac A
 
Burguer king
Burguer kingBurguer king
Burguer king
 
Literate Environment
Literate EnvironmentLiterate Environment
Literate Environment
 
Forma tradicional para el registro almacenamiento
Forma tradicional para el registro almacenamientoForma tradicional para el registro almacenamiento
Forma tradicional para el registro almacenamiento
 
Obra publica
Obra publicaObra publica
Obra publica
 
Riesgos de navegar en internet
Riesgos de navegar en internetRiesgos de navegar en internet
Riesgos de navegar en internet
 

Similar to Nantes JUG - Elasticsearch

Présentation de ElasticSearch / Digital apéro du 12/11/2014
Présentation de ElasticSearch / Digital apéro du 12/11/2014Présentation de ElasticSearch / Digital apéro du 12/11/2014
Présentation de ElasticSearch / Digital apéro du 12/11/2014Silicon Comté
 
Conférence Drupagora 2011: Drupal et les moteurs de recherche: Apache SolR
Conférence Drupagora 2011: Drupal et les moteurs de recherche: Apache SolRConférence Drupagora 2011: Drupal et les moteurs de recherche: Apache SolR
Conférence Drupagora 2011: Drupal et les moteurs de recherche: Apache SolRgwenael chichery
 
Toutes les raisons d'adopter MongoDB
Toutes les raisons d'adopter MongoDBToutes les raisons d'adopter MongoDB
Toutes les raisons d'adopter MongoDBContent Square
 
Big Data, Hadoop & Spark
Big Data, Hadoop & SparkBig Data, Hadoop & Spark
Big Data, Hadoop & SparkAlexia Audevart
 
GraphTour - Workday: Tracking activity with Neo4j (French version)
GraphTour - Workday: Tracking activity with Neo4j (French version)GraphTour - Workday: Tracking activity with Neo4j (French version)
GraphTour - Workday: Tracking activity with Neo4j (French version)Neo4j
 
Développement d'un moteur de recherche avec Zend Search
Développement d'un moteur de recherche avec Zend SearchDéveloppement d'un moteur de recherche avec Zend Search
Développement d'un moteur de recherche avec Zend SearchRobert Viseur
 
Jabes 2011 - Ateliers "Sudoc, Calames, thèses.fr et le web de données"
Jabes 2011 - Ateliers "Sudoc, Calames, thèses.fr et le web de données"Jabes 2011 - Ateliers "Sudoc, Calames, thèses.fr et le web de données"
Jabes 2011 - Ateliers "Sudoc, Calames, thèses.fr et le web de données"ABES
 
[GAB2016] Azure DocumentDB - Jean-Luc Boucho
[GAB2016] Azure DocumentDB - Jean-Luc Boucho[GAB2016] Azure DocumentDB - Jean-Luc Boucho
[GAB2016] Azure DocumentDB - Jean-Luc BouchoCellenza
 
Jean-Luc Boucho - Azure DocumentDB - Global Azure Bootcamp 2016 Paris
Jean-Luc Boucho - Azure DocumentDB - Global Azure Bootcamp 2016 Paris Jean-Luc Boucho - Azure DocumentDB - Global Azure Bootcamp 2016 Paris
Jean-Luc Boucho - Azure DocumentDB - Global Azure Bootcamp 2016 Paris AZUG FR
 
Nouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et Mobile
Nouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et MobileNouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et Mobile
Nouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et MobileIppon
 
Nouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et mobilité
Nouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et mobilitéNouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et mobilité
Nouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et mobilitéJulien Dubois
 
Tout ce que le getting started MongoDB ne vous dira pas
Tout ce que le getting started MongoDB ne vous dira pasTout ce que le getting started MongoDB ne vous dira pas
Tout ce que le getting started MongoDB ne vous dira pasBruno Bonnin
 
Devoxx: Tribulation d'un développeur sur le Cloud
Devoxx: Tribulation d'un développeur sur le CloudDevoxx: Tribulation d'un développeur sur le Cloud
Devoxx: Tribulation d'un développeur sur le CloudTugdual Grall
 
Web sémantique et Web de données, et si on passait à la pratique ?
Web sémantique et Web de données, et si on passait à la pratique ?Web sémantique et Web de données, et si on passait à la pratique ?
Web sémantique et Web de données, et si on passait à la pratique ?Antidot
 
Oxalide Academy : Workshop #3 Elastic Search
Oxalide Academy : Workshop #3 Elastic SearchOxalide Academy : Workshop #3 Elastic Search
Oxalide Academy : Workshop #3 Elastic SearchOxalide
 
Javascript as a first programming language : votre IC prête pour la révolution !
Javascript as a first programming language : votre IC prête pour la révolution !Javascript as a first programming language : votre IC prête pour la révolution !
Javascript as a first programming language : votre IC prête pour la révolution !VISEO
 

Similar to Nantes JUG - Elasticsearch (20)

Présentation de ElasticSearch / Digital apéro du 12/11/2014
Présentation de ElasticSearch / Digital apéro du 12/11/2014Présentation de ElasticSearch / Digital apéro du 12/11/2014
Présentation de ElasticSearch / Digital apéro du 12/11/2014
 
GetText / Rails - FR
GetText / Rails - FRGetText / Rails - FR
GetText / Rails - FR
 
GetText / Rails
GetText / RailsGetText / Rails
GetText / Rails
 
Conférence Drupagora 2011: Drupal et les moteurs de recherche: Apache SolR
Conférence Drupagora 2011: Drupal et les moteurs de recherche: Apache SolRConférence Drupagora 2011: Drupal et les moteurs de recherche: Apache SolR
Conférence Drupagora 2011: Drupal et les moteurs de recherche: Apache SolR
 
Toutes les raisons d'adopter MongoDB
Toutes les raisons d'adopter MongoDBToutes les raisons d'adopter MongoDB
Toutes les raisons d'adopter MongoDB
 
Big Data, Hadoop & Spark
Big Data, Hadoop & SparkBig Data, Hadoop & Spark
Big Data, Hadoop & Spark
 
GraphTour - Workday: Tracking activity with Neo4j (French version)
GraphTour - Workday: Tracking activity with Neo4j (French version)GraphTour - Workday: Tracking activity with Neo4j (French version)
GraphTour - Workday: Tracking activity with Neo4j (French version)
 
Développement d'un moteur de recherche avec Zend Search
Développement d'un moteur de recherche avec Zend SearchDéveloppement d'un moteur de recherche avec Zend Search
Développement d'un moteur de recherche avec Zend Search
 
Jabes 2011 - Ateliers "Sudoc, Calames, thèses.fr et le web de données"
Jabes 2011 - Ateliers "Sudoc, Calames, thèses.fr et le web de données"Jabes 2011 - Ateliers "Sudoc, Calames, thèses.fr et le web de données"
Jabes 2011 - Ateliers "Sudoc, Calames, thèses.fr et le web de données"
 
[GAB2016] Azure DocumentDB - Jean-Luc Boucho
[GAB2016] Azure DocumentDB - Jean-Luc Boucho[GAB2016] Azure DocumentDB - Jean-Luc Boucho
[GAB2016] Azure DocumentDB - Jean-Luc Boucho
 
Jean-Luc Boucho - Azure DocumentDB - Global Azure Bootcamp 2016 Paris
Jean-Luc Boucho - Azure DocumentDB - Global Azure Bootcamp 2016 Paris Jean-Luc Boucho - Azure DocumentDB - Global Azure Bootcamp 2016 Paris
Jean-Luc Boucho - Azure DocumentDB - Global Azure Bootcamp 2016 Paris
 
Nouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et Mobile
Nouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et MobileNouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et Mobile
Nouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et Mobile
 
Nouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et mobilité
Nouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et mobilitéNouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et mobilité
Nouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et mobilité
 
NodeJs in real life
NodeJs in real lifeNodeJs in real life
NodeJs in real life
 
Tout ce que le getting started MongoDB ne vous dira pas
Tout ce que le getting started MongoDB ne vous dira pasTout ce que le getting started MongoDB ne vous dira pas
Tout ce que le getting started MongoDB ne vous dira pas
 
Devoxx: Tribulation d'un développeur sur le Cloud
Devoxx: Tribulation d'un développeur sur le CloudDevoxx: Tribulation d'un développeur sur le Cloud
Devoxx: Tribulation d'un développeur sur le Cloud
 
Web sémantique et Web de données, et si on passait à la pratique ?
Web sémantique et Web de données, et si on passait à la pratique ?Web sémantique et Web de données, et si on passait à la pratique ?
Web sémantique et Web de données, et si on passait à la pratique ?
 
Oxalide Academy : Workshop #3 Elastic Search
Oxalide Academy : Workshop #3 Elastic SearchOxalide Academy : Workshop #3 Elastic Search
Oxalide Academy : Workshop #3 Elastic Search
 
Elastic serach
Elastic serachElastic serach
Elastic serach
 
Javascript as a first programming language : votre IC prête pour la révolution !
Javascript as a first programming language : votre IC prête pour la révolution !Javascript as a first programming language : votre IC prête pour la révolution !
Javascript as a first programming language : votre IC prête pour la révolution !
 

More from David Pilato

2018-10-02 - Un moteur de recherche NoSQL pour chercher^H^H^H^H^H^H^H^H trouv...
2018-10-02 - Un moteur de recherche NoSQL pour chercher^H^H^H^H^H^H^H^H trouv...2018-10-02 - Un moteur de recherche NoSQL pour chercher^H^H^H^H^H^H^H^H trouv...
2018-10-02 - Un moteur de recherche NoSQL pour chercher^H^H^H^H^H^H^H^H trouv...David Pilato
 
Managing your black friday logs Voxxed Luxembourg
Managing your black friday logs Voxxed LuxembourgManaging your black friday logs Voxxed Luxembourg
Managing your black friday logs Voxxed LuxembourgDavid Pilato
 
Un moteur de recherche NoSQL pour chercher^H^H^H^H^H^H^H^H trouver...
Un moteur de recherche NoSQL pour chercher^H^H^H^H^H^H^H^H trouver...Un moteur de recherche NoSQL pour chercher^H^H^H^H^H^H^H^H trouver...
Un moteur de recherche NoSQL pour chercher^H^H^H^H^H^H^H^H trouver...David Pilato
 
Managing your Black Friday Logs NDC Oslo
Managing your  Black Friday Logs NDC OsloManaging your  Black Friday Logs NDC Oslo
Managing your Black Friday Logs NDC OsloDavid Pilato
 
Managing your black friday logs - Code Europe
Managing your black friday logs - Code EuropeManaging your black friday logs - Code Europe
Managing your black friday logs - Code EuropeDavid Pilato
 
Managing your black Friday logs - CloudConf.IT
Managing your black Friday logs - CloudConf.ITManaging your black Friday logs - CloudConf.IT
Managing your black Friday logs - CloudConf.ITDavid Pilato
 
Elastify you application: from SQL to NoSQL in less than one hour!
Elastify you application: from SQL to NoSQL in less than one hour!Elastify you application: from SQL to NoSQL in less than one hour!
Elastify you application: from SQL to NoSQL in less than one hour!David Pilato
 
Elasticsearch - Devoxx France 2012 - English version
Elasticsearch - Devoxx France 2012 - English versionElasticsearch - Devoxx France 2012 - English version
Elasticsearch - Devoxx France 2012 - English versionDavid Pilato
 

More from David Pilato (8)

2018-10-02 - Un moteur de recherche NoSQL pour chercher^H^H^H^H^H^H^H^H trouv...
2018-10-02 - Un moteur de recherche NoSQL pour chercher^H^H^H^H^H^H^H^H trouv...2018-10-02 - Un moteur de recherche NoSQL pour chercher^H^H^H^H^H^H^H^H trouv...
2018-10-02 - Un moteur de recherche NoSQL pour chercher^H^H^H^H^H^H^H^H trouv...
 
Managing your black friday logs Voxxed Luxembourg
Managing your black friday logs Voxxed LuxembourgManaging your black friday logs Voxxed Luxembourg
Managing your black friday logs Voxxed Luxembourg
 
Un moteur de recherche NoSQL pour chercher^H^H^H^H^H^H^H^H trouver...
Un moteur de recherche NoSQL pour chercher^H^H^H^H^H^H^H^H trouver...Un moteur de recherche NoSQL pour chercher^H^H^H^H^H^H^H^H trouver...
Un moteur de recherche NoSQL pour chercher^H^H^H^H^H^H^H^H trouver...
 
Managing your Black Friday Logs NDC Oslo
Managing your  Black Friday Logs NDC OsloManaging your  Black Friday Logs NDC Oslo
Managing your Black Friday Logs NDC Oslo
 
Managing your black friday logs - Code Europe
Managing your black friday logs - Code EuropeManaging your black friday logs - Code Europe
Managing your black friday logs - Code Europe
 
Managing your black Friday logs - CloudConf.IT
Managing your black Friday logs - CloudConf.ITManaging your black Friday logs - CloudConf.IT
Managing your black Friday logs - CloudConf.IT
 
Elastify you application: from SQL to NoSQL in less than one hour!
Elastify you application: from SQL to NoSQL in less than one hour!Elastify you application: from SQL to NoSQL in less than one hour!
Elastify you application: from SQL to NoSQL in less than one hour!
 
Elasticsearch - Devoxx France 2012 - English version
Elasticsearch - Devoxx France 2012 - English versionElasticsearch - Devoxx France 2012 - English version
Elasticsearch - Devoxx France 2012 - English version
 

Nantes JUG - Elasticsearch

  • 1. Elasticsearch. Le moteur de recherche élastique pour tous David Pilato, IDEO Technologies, Paris mardi 5 février 13
  • 2. Qui ? $ curl http://localhost:9200/talk/speaker/dpilato { "nom" : "David Pilato", "jobs" : [ { "boite" : "SRA Europe (SSII)", "mission" : "bon à tout faire", "duree" : 3 }, { "boite" : "SFR", "mission" : "touche à tout", "duree" : 3 }, { "boite" : "e-Brands / Vivendi", "mission" : "chef de projets", "duree" : 4 }, { "boite" : "DGDDI (douane)", "mission" : "mouton à 5 pattes", "duree" : 8 }, { "boite" : "IDEO Technologies", "mission" : "directeur technique", "duree" : 0 } ], "passions" : [ "famille", "job", "deejay" ], "blog" : "http://dev.david.pilato.fr/", "twitter" : [ "@dadoonet", "@elasticsearchfr", "@scrutmydocs" ], "email" : "david@pilato.fr" } mardi 5 février 13
  • 4. Pour la démo Faites du bruit sur Twitter avec le hashtag #elasticsearch mardi 5 février 13
  • 5. SQL Classique Cherche moi un document de décembre 2011 portant sur la france et contenant produit et david En SQL : SELECT doc.*, pays.* FROM doc, pays WHERE doc.pays_code = pays.code AND doc.date_doc > to_date('2011-12', 'yyyy-mm') AND doc.date_doc < to_date('2012-01', 'yyyy-mm') AND lower(pays.libelle) = 'france' AND lower(doc.commentaire) LIKE ‘%produit%' AND lower(doc.commentaire) LIKE ‘%david%'; mardi 5 février 13
  • 6. Les limites de la recherche SQL • Performances désastreuses sur du like % sur des millions de ligne • Plombe les performances de l’insertion • Pas de tolérance aux fotes de frappe • En général, on se limite aux champs figés ou codifiés • Recherche « google » impossible ! mardi 5 février 13
  • 7. Au final, on obtient • Autrement dit : tu as intérêt à savoir ce que tu cherches ! • Fouiller est interdit ! mardi 5 février 13
  • 8. Un moteur de recherche • Un moteur de recherche est composé de : • un moteur d’indexation de documents • un moteur de recherche sur les index • De fait, un moteur de recherche est énormément plus rapide qu’une base de données pour faire des recherches : c’est son métier ! mardi 5 février 13
  • 9. L’indexation, c’est quoi en fait ? mardi 5 février 13
  • 10. Elasticsearch Your Data, your Search ! mardi 5 février 13
  • 11. Elasticsearch • Moteur de recherche pour la génération NoSQL • Basé sur le standard Apache Lucene • Masque la complexité Java/Lucene à l’aide de services standards HTTP / RESTful / JSON • Utilisable à partir de n’importe quelle technologie • Ajoute la couche cloud manquante à Lucene • C’est un moteur, pas une interface graphique ! mardi 5 février 13
  • 12. Points clés • Simple ! En quelques minutes (Zero Conf), on dispose d’un moteur complet prêt à recevoir nos documents à indexer et à faire des recherches. • Efficace ! Il suffit de démarrer des nœuds Elasticsearch pour bénéficier immédiatement de la réplication, de l’équilibrage de charge. • Puissant ! Basé sur Lucene, il en parallélise les traitements pour donner des temps de réponse acceptables (en général inférieurs à 100ms) • Complet ! Beaucoup de fonctionnalités : analyse et facettes, percolation, rivières, plugins, … mardi 5 février 13
  • 13. Ranger ses données • Document : Un objet représentant les données (au sens NoSQL). Penser "recherche", c'est oublier le SGBDR et penser "Documents" { "text": "Bienvenue à la conférence #elasticsearch pour #JUG", "created_at": "2012-04-06T20:45:36.000Z", "source": "Twitter for iPad", "truncated": false, "retweet_count": 0, "hashtag": [ { "text": "elasticsearch", "start": 27, "end": 40 }, { "text": "JUG", "start": 47, "end": 55 } ], "user": { "id": 51172224, "name": "David Pilato", "screen_name": "dadoonet", "location": "France", "description": "Soft Architect, Project Manager, Senior Developper.rnAt this time, enjoying NoSQL world : CouchDB, ElasticSearch.rnDeeJay 4 times a year, just for fun !" } } • Type : Regroupe des documents de même type • Index : Espace logique de stockage des documents dont les types sont fonctionnellement communs mardi 5 février 13
  • 14. Interagir avec Elasticsearch • API REST : http://host:port/[index]/[type]/[_action/id] Méthodes HTTP : GET, POST, PUT, DELETE • Documents • curl -XPUT http://localhost:9200/twitter/tweet/1 • curl -XGET http://localhost:9200/twitter/tweet/1 • curl -XDELETE http://localhost:9200/twitter/tweet/1 • Recherche • curl -XPOST http://localhost:9200/twitter/tweet/_search • curl -XPOST http://localhost:9200/twitter/_search • curl -XPOST http://localhost:9200/_search • Meta-données • curl -XGET http://localhost:9200/twitter/_status • curl -XPOST http://localhost:9200/_shutdown mardi 5 février 13
  • 15. Indexer $ curl -XPUT localhost:9200/twitter/tweet/1 -d ' { "text": "Bienvenue à la conférence #elasticsearch pour #JUG", "created_at": "2012-04-06T20:45:36.000Z", "source": "Twitter for iPad", "truncated": false, "retweet_count": 0, "hashtag": [ { "text": "elasticsearch", "start": 27, "end": 40 }, { "text": "JUG", "start": 47, "end": 55 } ], "user": { "id": 51172224, "name": "David Pilato", "screen_name": "dadoonet", "location": "France", "description": "Soft Architect, Project Manager, Senior Developper.r nAt this time, enjoying NoSQL world : CouchDB, ElasticSearch.rnDeeJay 4 times a year, just for fun !" } }' { "ok":true, "_index":"twitter", "_type":"tweet", "_id":"1" } mardi 5 février 13
  • 16. Chercher $ curl localhost:9200/twitter/tweet/_search?q=elasticsearch { "took" : 24, Nb de "timed_out" : false, documents "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 1, Document "max_score" : 0.227, "hits" : [ { Coordonnées source "_index" : "twitter", "_type" : "tweet", "_id" : "1", "_score" : 0.227, "_source" : { "text": "Bienvenue à la conférence #elasticsearch pour #JUG", "created_at": "2012-04-06T20:45:36.000Z", "source": "Twitter for iPad", […] } Pertinence } ] } } mardi 5 février 13
  • 17. Les résultats • Elasticsearch renvoie les 10 premiers résultats. Il fournit l’API permettant de naviguer de page en page (from, size) • Par défaut, le tri est réalisé sur le score de pertinence mardi 5 février 13
  • 18. Query DSL • Requêtes précises : plutôt que de chercher « à la google », on peut utiliser des critères précis : $ curl -XPOST localhost:9200/twitter/tweet/_search -d ’{ "bool" : { "must" : { "term" : { "user" : "kimchy" } }, "must_not" : { "range" : { "age" : { "from" : 10, "to" : 20 } } }, "should" : [ { "term" : { "tag" : "wow" } },{ "match" : { "tag" : "elasticsearch is cool" } } ] } }’ mardi 5 février 13
  • 19. Injecter les données Et au milieu coule une rivière mardi 5 février 13
  • 20. La collecte Doc Stockage Données mardi 5 février 13
  • 21. La collecte Doc Stockage Données Doc mardi 5 février 13
  • 22. La collecte Stockage Données Doc Doc mardi 5 février 13
  • 23. La collecte Doc Stockage Données Doc Doc mardi 5 février 13
  • 24. La collecte Stockage Données Doc Doc mardi 5 février 13
  • 25. La collecte Stockage Données Doc Doc mardi 5 février 13
  • 26. Quelques Rivers... • CouchDB River • CouchBase River • MongoDB River • JDBC River • Wikipedia River • Twitter River • RabbitMQ River • ActiveMQ River • RSS River • LDAP River • FS River • Dropbox River • Dick Rivers mardi 5 février 13
  • 27. Analyser La puissance des facettes ! Faites parler vos données en les regardant sous différentes facettes ! (Et en temps quasi réel, s’il vous plait !) mardi 5 février 13
  • 28. Des tweets ID Username Date Hashtag 1 dadoonet 2012-04-18 1 2 ideo 2012-04-18 5 3 elasticsearch 2012-04-18 2 4 dadoonet 2012-04-18 2 5 ideo 2012-04-18 6 6 elasticsearch 2012-04-19 3 7 dadoonet 2012-04-19 3 8 ideo 2012-04-19 7 9 elasticsearch 2012-04-20 4 mardi 5 février 13
  • 29. Term Facet D Username Date Hashtag 1 dadoonet 2012-04-18 1 2 ideo 2012-04-18 5 3 elasticsearch 2012-04-18Username 2 Count 4 dadoonet 2012-04-18dadoonet 2 3 5 ideo 2012-04-18 ideo 6 3 6 elasticsearch 2012-04-19 elasticsearch 3 3 7 dadoonet 2012-04-19 3 8 ideo 2012-04-19 7 9 elasticsearch 2012-04-20 4 mardi 5 février 13
  • 30. Term Facet D Username Date Hashtag 1 dadoonet 2012-04-18 "facets" : { 1 "users" : { "terms" : {"field" : "username"} } } 2 ideo 2012-04-18 5 "facets" : { 3 elasticsearch 2012-04-18 "users" : { 2 "_type" : "terms", 4 dadoonet 2012-04-18"missing" : 0,2 "total": 9, 5 ideo 2012-04-18"other": 0, 6 "terms" : [ 6 elasticsearch 2012-04-19 { "term" : "dadoonet", "count" },3 }, 3 { "term" : "ideo", "count" : 3 : { "term" : "elasticsearch", "count" : 3 } 7 dadoonet 2012-04-19] 3 } 8 ideo 2012-04-19 } 7 9 elasticsearch 2012-04-20 4 mardi 5 février 13
  • 31. Date Histogram Facet Date Hashtag 2012-04-18 1 Par mois 2012-04-18 5 Date Count h 2012-04-18 2 2012-04 9 2012-04-18 2 2012-04-18 6 Par jour h 2012-04-19 3 Date Count 2012-04-19 3 2012-04-18 5 2012-04-19 7 2012-04-19 3 h 2012-04-20 4 2012-04-20 1 mardi 5 février 13
  • 32. Date Histogram Facet Date Hashtag "facets" : { 2012-04-18 1 "perday" : { "date_histogram" : { 2012-04-18 5 "field" : "date", "interval" : "day" } h 2012-04-18 2 } } 2012-04-18 2 "facets" : { 2012-04-18 6 "perday" : { "_type" : "date_histogram", h 2012-04-19 3 "entries": [ { "time": 1334700000000, "count": 5 }, 2012-04-19 3 { "time": 1334786400000, "count": 3 }, { "time": 1334872800000, "count": 1 } 2012-04-19 7 } ] } h 2012-04-20 4 mardi 5 février 13
  • 33. Range Facet Hashtag 1 5 2 Hashtag Count Min Max Moy Total 2 x<3 3 1 2 1.667 5 6 3 <= x < 5 3 3 4 3.333 10 3 x >= 5 3 5 7 6 18 3 7 4 mardi 5 février 13
  • 34. Range Facet "facets" : { "hashtags" : { "range" : { "field" : "hashtag", "ranges" : [ { "to" : 3 }, Hashtag { "from" : 3, "to" : 5 }, { "from" : 5 } ] } } } 1 "facets" : { 5 "hashtags" : { "_type" : "range", 2 "ranges" : [ { "to": 3, 2 "count": 3, "min": 1, "max": 2, 6 "total": 5, "mean": 1.667 }, { "from":3, "to" : 5, 3 "count": 3, "min": 3, "max": 4, 3 "total": 10, "mean": 3.333 },{ 7 "from":5, "count": 3, 4 "min": 5, "max": 7, "total": 18, "mean": 6 } ] } } mardi 5 février 13
  • 35. Site marchand Ranges Term Term Ranges mardi 5 février 13
  • 36. Analyse temps-réel • Faire un matchAll sur l'ensemble des données • Actualiser toutes les x secondes • Indexer en même temps les nouvelles données Date histogram Term mardi 5 février 13
  • 37. Facettes Cartographiques mardi 5 février 13
  • 38. Reprenons notre formulaire Recherche Full Text mardi 5 février 13
  • 39. Reprenons notre formulaire mardi 5 février 13
  • 40. Démonstration Avez-vous fait du bruit ? mardi 5 février 13
  • 41. Architecture Chrome Twitter Twitter Streaming River API $ curl -XPUT localhost:9200/_river/twitter/_meta -d ' { "type" : "twitter", "twitter" : { "user" : "twitter_user", "password" : "twitter_password", "filter" : { "tracks" : ["elasticsearch"] } } }' mardi 5 février 13
  • 42. Démonstration http://onemilliontweetmap.com/ mardi 5 février 13
  • 43. Architecture Un peu plus de technique : partitions / réplications / scalabilité mardi 5 février 13
  • 44. Lexique • Nœud (node) : Une instance d'Elasticsearch (~ machine ?) • Cluster : Un ensemble de nœuds • Partition (shard) : permet de découper un index en plusieurs parties pour y distribuer les documents • Réplication (replica) : recopie d’une partition en une ou plusieurs copies dans l'ensemble du cluster • Partition primaire (primary shard) : partition élue "principale" dans l'ensemble du cluster. C'est là que se fait l'indexation par Lucene. Il n'y en a qu'une seule par shard dans l'ensemble du cluster. • Partition secondaire (secondary shard) : partitions secondaires stockant les replicas des partitions primaires. mardi 5 février 13
  • 45. Créons un index $ curl -XPUT localhost:9200/twitter -d '{ Cluster "index" : { Nœud 1 Nœud 1 Nœud 2 "number_of_shards" : 2, "number_of_replicas" : 1 Shard 00 Shard Shard 0 } Shard 11 Shard }' Shard 1 réplication non respectée réplication respectée Client CURL mardi 5 février 13
  • 46. Réallocation dynamique Cluster Nœud 1 Nœud 2 Nœud 3 Shard 0 Shard 0 Shard 1 Shard 1 mardi 5 février 13
  • 47. Réallocation dynamique Cluster Nœud 1 Nœud 2 Nœud 3 Shard 0 Shard 0 Shard 0 Shard 1 Shard 1 mardi 5 février 13
  • 48. Réallocation dynamique Cluster Nœud 1 Nœud 2 Nœud 3 Nœud 4 Shard 0 Shard 0 Shard 1 Shard 1 mardi 5 février 13
  • 49. Réallocation dynamique Cluster Nœud 1 Nœud 2 Nœud 3 Nœud 4 Shard 0 Shard 0 Shard 1 Shard 1 Shard 1 Le tuning, c'est trouver le bon équilibre entre le nombre de nodes, shards et replicas ! mardi 5 février 13
  • 50. Indexons un document Cluster Nœud 1 Nœud 2 Nœud 3 Nœud 4 Shard 0 Shard 0 Shard 1 Shard 1 Doc 1 Client $ curl -XPUT localhost:9200/twitter/tweet/1 -d ' CURL { "text": "Bienvenue à la conférence #elasticsearch pour #JUG", "created_at": "2012-04-06T20:45:36.000Z", "source": "Twitter for iPad", ... }' mardi 5 février 13
  • 51. Indexons un document Cluster Nœud 1 Nœud 2 Nœud 3 Nœud 4 Doc Shard 0 1 Shard 0 Shard 1 Shard 1 Client $ curl -XPUT localhost:9200/twitter/tweet/1 -d ' CURL { "text": "Bienvenue à la conférence #elasticsearch pour #JUG", "created_at": "2012-04-06T20:45:36.000Z", "source": "Twitter for iPad", ... }' mardi 5 février 13
  • 52. Indexons un document Cluster Nœud 1 Nœud 2 Nœud 3 Nœud 4 Doc Doc Shard 0 1 Shard 0 1 Shard 1 Shard 1 Client $ curl -XPUT localhost:9200/twitter/tweet/1 -d ' CURL { "text": "Bienvenue à la conférence #elasticsearch pour #JUG", "created_at": "2012-04-06T20:45:36.000Z", "source": "Twitter for iPad", ... }' mardi 5 février 13
  • 53. Indexons un 2ème document Cluster Nœud 1 Nœud 2 Nœud 3 Nœud 4 Doc Doc Shard 0 1 Shard 0 1 Shard 1 Shard 1 Doc 2 Client $ curl -XPUT localhost:9200/twitter/tweet/2 -d ' CURL { "text": "Je fais du bruit pour #elasticsearch à #JUG", "created_at": "2012-04-06T21:12:52.000Z", "source": "Twitter for iPad", ... }' mardi 5 février 13
  • 54. Indexons un 2ème document Cluster Nœud 1 Nœud 2 Nœud 3 Nœud 4 Doc Doc Shard 0 1 Shard 0 1 Shard 1 Shard 1 Doc 2 Client $ curl -XPUT localhost:9200/twitter/tweet/2 -d ' CURL { "text": "Je fais du bruit pour #elasticsearch à #JUG", "created_at": "2012-04-06T21:12:52.000Z", "source": "Twitter for iPad", ... }' mardi 5 février 13
  • 55. Indexons un 2ème document Cluster Nœud 1 Nœud 2 Nœud 3 Nœud 4 Doc Doc Shard 0 1 Shard 0 1 Shard 1 Doc Shard 1 2 Client $ curl -XPUT localhost:9200/twitter/tweet/2 -d ' CURL { "text": "Je fais du bruit pour #elasticsearch à #JUG", "created_at": "2012-04-06T21:12:52.000Z", "source": "Twitter for iPad", ... }' mardi 5 février 13
  • 56. Indexons un 2ème document Cluster Nœud 1 Nœud 2 Nœud 3 Nœud 4 Doc Doc Shard 0 1 Shard 0 1 Doc Doc Shard 1 Shard 1 2 2 Client $ curl -XPUT localhost:9200/twitter/tweet/2 -d ' CURL { "text": "Je fais du bruit pour #elasticsearch à #JUG", "created_at": "2012-04-06T21:12:52.000Z", "source": "Twitter for iPad", ... }' mardi 5 février 13
  • 57. Cherchons ! Cluster Nœud 1 Nœud 2 Nœud 3 Nœud 4 Doc Doc Shard 0 1 Shard 0 1 Doc Doc Shard 1 Shard 1 2 2 Client $ curl localhost:9200/twitter/_search?q=elasticsearch CURL mardi 5 février 13
  • 58. Cherchons ! Cluster Nœud 1 Nœud 2 Nœud 3 Nœud 4 Doc Shard 0 Shard 0 1 Doc Shard 1 Shard 1 Doc 2 Doc 1 2 Client $ curl localhost:9200/twitter/_search?q=elasticsearch CURL mardi 5 février 13
  • 59. Cherchons ! { Cluster "took" : 24, Nœud 1 "timed_out" : false,Nœud 3 Nœud 2 Nœud 4 "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, Doc Shard 0 "hits" : { Shard 0 1 "total" : 2, "max_score" : 0.227, Doc Shard 1 "hits" : [ { Shard 1 2 "_index" : "twitter", "_type" : "tweet", "_id" : "1", "_score" : 0.227, "_source" : { ... } Doc }, { Doc 2 "_index" : "twitter", 1 Client "_type" : "tweet", $ curl localhost:9200/twitter/_search?q=elasticsearch CURL "_id" : "2", "_score" : 0.152, "_source" : { ... } } ] } mardi 5 février 13
  • 60. Cherchons encore ! Cluster Nœud 1 Nœud 2 Nœud 3 Nœud 4 Doc Doc Shard 0 1 Shard 0 1 Doc Doc Shard 1 Shard 1 2 2 Client $ curl localhost:9200/twitter/_search?q=elasticsearch CURL mardi 5 février 13
  • 61. Cherchons encore ! Cluster Nœud 1 Nœud 2 Nœud 3 Nœud 4 Doc Shard 0 1 Shard 0 Doc 1 Shard 1 Doc Doc Shard 1 2 2 Client $ curl localhost:9200/twitter/_search?q=elasticsearch CURL mardi 5 février 13
  • 62. Cherchons encore ! Cluster Nœud 1 Nœud 2 Nœud 3 Doc Shard 0 1 Shard 0 Shard 1 Doc Doc 1 2 Client $ curl localhost:9200/twitter/_search?q=elasticsearch CURL mardi 5 février 13
  • 63. Cherchons encore ! { Cluster "took" : 24, Nœud 1 "timed_out" : false,Nœud 3 Nœud 2 "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, Doc Shard 0 1 "hits" : { Shard 0 "total" : 2, "max_score" : 0.227, Shard 1 "hits" : [ { "_index" : "twitter", "_type" : "tweet", "_id" : "1", "_score" : 0.227, "_source" : { ... } Doc }, { 2 Doc "_index" : "twitter", 1 Client "_type" : "tweet", $ curl localhost:9200/twitter/_search?q=elasticsearch CURL "_id" : "2", "_score" : 0.152, "_source" : { ... } } ] } mardi 5 février 13
  • 64. La percolation Ou la recherche inversée mardi 5 février 13
  • 65. Usage courant d’un moteur de recherche • J’indexe un document • Je cherche de temps en temps si un document m’intéresse • Avec de la chance, il sera bien placé au niveau pertinence dans les résultats. Sinon, il passe inaperçu ! mardi 5 février 13
  • 66. La recherche inversée • Enregistrer ses critères de recherche • A chaque document indexé, on récupère la liste des recherches qui correspondent • On a un « listener » sur le moteur d’indexation : le percolator mardi 5 février 13
  • 67. Usage du percolator $ curl -XPOST localhost:9200/_percolator/twitter/dadoonet -d ’{ "query" : { "term" : { "user.screen_name" : "dadoonet" } } }’ $ curl -XPOST localhost:9200/_percolator/twitter/elasticsearch -d ’{ "query" : { "match" : { "hashtag.text" : "elasticsearch" } } }’ $ curl -XPOST localhost:9200/_percolator/twitter/mycomplexquery -d ’{ "query" : { "bool" : { "must" : { "term" : { "user" : "kimchy" } }, "must_not" : { "range" : { "age" : { "from" : 10, "to" : 20 } } }, "should" : [ { "term" : { "tag" : "wow" } },{ "match" : { "tag" : "elasticsearch is cool" } } ] } } }’ mardi 5 février 13
  • 68. Usage du percolator $ curl -XPUT localhost:9200/twitter/tweet/1&percolate=* -d '{ "text": "Bienvenue à la conférence #elasticsearch pour #JUG", "created_at": "2012-04-06T20:45:36.000Z", "source": "Twitter for iPad", "truncated": false, "retweet_count": 0, "hashtag": [ { "text": "elasticsearch", "start": 27, "end": 40 }, { "text": "JUG", "start": 47, "end": 55 } ], "user": { "id": 51172224, "name": "David Pilato", "screen_name": "dadoonet", "location": "France", "description": "Soft Architect, Project Manager, Senior Developper.rnAt this time, enjoying NoSQL world : CouchDB, ElasticSearch.r nDeeJay 4 times a year, just for fun !" } }' { "ok": true, "_index": "twitter", "_type": "tweet", "_id": "1", "matches": [ "dadoonet", "elasticsearch" ] } mardi 5 février 13
  • 69. Tout doit être indexé ? Analyse et mapping mardi 5 février 13
  • 70. The lazy dog... The quick brown fox jumped over the lazy Dog The quick brown fox jumped over the lazy dog mardi 5 février 13
  • 71. Analyseur standard $ curl -XPOST 'localhost:9200/test/_analyze?analyzer=standard&pretty=1' -d 'The quick brown fox jumped over the lazy Dog' { "tokens" : [ { "token" : "quick", "start_offset": 4, "end_offset": 9, "type": "<ALPHANUM>", "position": 2 }, { "token" : "brown", "start_offset": 10, "end_offset": 15, "type": "<ALPHANUM>", "position": 3 }, { "token" : "fox", "start_offset": 16, "end_offset": 19, "type": "<ALPHANUM>", "position": 4 }, { "token": "jumped", "start_offset": 20, "end_offset": 26, "type": "<ALPHANUM>", "position": 5 }, { "token": "over", "start_offset": 27, "end_offset": 31, "type": "<ALPHANUM>", "position": 6 }, { "token" : "lazy", "start_offset": 36, "end_offset": 40, "type": "<ALPHANUM>", "position": 8 }, { "token" : "dog", "start_offset": 41, "end_offset": 44, "type": "<ALPHANUM>", "position": 9 } ] } mardi 5 février 13
  • 72. Analyseur whitespace $ curl -XPOST 'localhost:9200/test/_analyze?analyzer=whitespace&pretty=1' -d 'The quick brown fox jumped over the lazy Dog' { "tokens" : [ { "token" : "The", ... }, { "token" : "quick", ... }, { "token" : "brown", ... }, { "token" : "fox", ... }, { "token" : "jumped", ... }, { "token" : "over", ... }, { "token" : "the", ... }, { "token" : "lazy", ... }, { "token" : "Dog", ... } ] } mardi 5 février 13
  • 73. Un analyseur Un ensemble de tokenizers et de filtres mardi 5 février 13
  • 74. Un tokenizer • Découpe une chaine en « mots » et transforme : • whitespace tokenizer : "the dog!" -> "the", "dog!" • standard tokenizer : "the dog!" -> "the", "dog" mardi 5 février 13
  • 75. Un filtre • Supprime ou transforme un token : • asciifolding filter : éléphant -> elephant • stemmer filter (french) : elephants -> "eleph" cheval -> "cheval" chevaux -> "cheval" • phonetic (plugin) : quick -> "Q200" quik -> "Q200" mardi 5 février 13
  • 76. Analyzer "analysis":{ "analyzer":{ "francais":{ "type":"custom", "tokenizer":"standard", "filter":["lowercase", "stop_francais", "fr_stemmer", "asciifolding", "elision"] } }, "filter":{ "stop_francais":{ "type":"stop", "stopwords":["_french_", "twitter"] }, "fr_stemmer" : { "type" : "stemmer", "name" : "french" }, "elision" : { "type" : "elision", "articles" : ["l", "m", "t", "qu", "n", "s", "j", "d"] } } } mardi 5 février 13
  • 77. Mapping "type1" : { "properties" : { "text1" : { "type" : "string", "analyzer" : "simple" }, "text2" : { "type" : "string", "index_analyzer" : "simple", "search_analyzer" : "standard" }, "text3" : { "type" : "multi_field", "fields" : { "text3" : { "type" : "string", "analyzer" : "standard" }, "ngram" : { "type" : "string", "analyzer" : "ngram" }, "soundex" : { "type" : "string", "analyzer" : "soundex" } } } } } mardi 5 février 13
  • 78. Les types • string • multi_field • integer / long • ip • float / double • geo_point • boolean • geo_shape • null • binary • array • attachment (plugin) • objects mardi 5 février 13
  • 79. Champs spéciaux • _all (et include_in_all) • _source • _ttl • parent / child • nested mardi 5 février 13
  • 80. Autres fonctionnalités • highlighting • scoring • sort • explain • multi get / multi search • bulk mardi 5 février 13
  • 81. Démonstrations www.scrutmydocs.org CURL est ton ami ! JAVA est aussi ton ami ! mardi 5 février 13
  • 82. La communauté ~100 contributeurs directs au projet (+ de 2800 watchers et + de 470 forks) mardi 5 février 13
  • 83. Rejoignez le mouvement ! @ElasticsearchFR www.elasticsearch.fr ss re og pr in Questions ? Posez aussi vos questions sur elasticsearch-fr@googlegroups.com Slides sur http://fr.slideshare.net/dadoonet Sources sur https://github.com/dadoonet/talks mardi 5 février 13