SlideShare une entreprise Scribd logo
Elasticsearch.
                     Le moteur de recherche
                       élastique pour tous




David Pilato, IDEO Technologies, Paris
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"
}
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"
}
ScrutMyDocs.org
Pour la démo


 Faites du bruit sur Twitter
      avec le hashtag


#elasticsearch
SQL Classique
        Cherche moi un document
 de décembre 2011 portant sur la france
      et contenant produit et david
En SQL :
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%';
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 !
Au final, on obtient

             • Autrement dit :
               tu as intérêt à
               savoir ce que
               tu cherches !
             • Fouiller est
               interdit !
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 !
L’indexation, c’est quoi
       en fait ?
Elasticsearch
Elasticsearch
   Your Data, your Search !
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 !
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, …
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"




• Type : Regroupe des documents de même type
• Index : Espace logique de stockage des documents dont les
   types sont fonctionnellement communs
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
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
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
Interagir avec
Elasticsearch
Interagir avec
              Elasticsearch
•   API REST : http://host:port/[index]/[type]/[_action/id]
    Méthodes HTTP : GET, POST, PUT, DELETE
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
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
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
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
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
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
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
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
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 !" }
}'
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"
}
Chercher
$ curl localhost:9200/twitter/tweet/_search?q=elasticsearch
Chercher
    $ curl localhost:9200/twitter/tweet/_search?q=elasticsearch




{
    "took" : 24,
    "timed_out" : false,
    "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 },
    "hits" : {
      "total" : 1,
      "max_score" : 0.227,
      "hits" : [ {
        "_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",
          […]
        }
      } ]
    }
}
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,
      "max_score" : 0.227,
      "hits" : [ {
        "_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",
          […]
        }
      } ]
    }
}
Chercher
    $ curl localhost:9200/twitter/tweet/_search?q=elasticsearch




{
    "took" : 24,
    "timed_out" : false,
    "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 },
    "hits" : {
      "total" : 1,
      "max_score" : 0.227,
      "hits" : [ {                          Coordonnées
        "_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",
          […]
        }
      } ]
    }
}
Chercher
    $ curl localhost:9200/twitter/tweet/_search?q=elasticsearch




{
    "took" : 24,
    "timed_out" : false,
    "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 },
    "hits" : {
      "total" : 1,
      "max_score" : 0.227,
      "hits" : [ {
        "_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
      } ]
    }
}
Chercher
    $ curl localhost:9200/twitter/tweet/_search?q=elasticsearch




{
    "took" : 24,
    "timed_out" : false,
    "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 },
    "hits" : {
      "total" : 1,                                           Document
      "max_score" : 0.227,
      "hits" : [ {
                                                              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",
          […]
        }
      } ]
    }
}
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
Query DSL
• Requêtes précises : plutôt que de
  chercher « à la google », on peut
  utiliser des critères précis :
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" }
              }
          ]
      }
  }’
Injecter les données
   Et au milieu coule une rivière
La collecte
La collecte


    Stockage
    Données
La collecte


Doc
          Stockage
          Données
La collecte


     Stockage
     Données
    Doc
La collecte


Doc
           Stockage
           Données
          Doc
La collecte


     Stockage
     Données
    Doc   Doc
La collecte


     Stockage
     Données
    Doc   Doc
La collecte


     Stockage
     Données
    Doc   Doc
La collecte


    Stockage
    Données

      Doc



      Doc
La collecte

Doc

          Stockage
          Données

            Doc



            Doc
La collecte


    Stockage
    Données
      Doc




      Doc
La collecte


    Stockage
    Données




      Doc
      Doc
Quelques Rivers...
Quelques Rivers...
• CouchDB River
Quelques Rivers...
• CouchDB River
• MongoDB River
Quelques Rivers...
• CouchDB River
• MongoDB River
• JDBC River
Quelques Rivers...
• CouchDB River
• MongoDB River
• JDBC River
• Wikipedia River
Quelques Rivers...
• CouchDB River
• MongoDB River
• JDBC River
• Wikipedia River
• Twitter River
Quelques Rivers...
• CouchDB River
• MongoDB River
• JDBC River
• Wikipedia River
• Twitter River
• RabbitMQ River
Quelques Rivers...
• CouchDB River
• MongoDB River
• JDBC River
• Wikipedia River
• Twitter River
• RabbitMQ River
• ActiveMQ River
Quelques Rivers...
• CouchDB River
• MongoDB River
• JDBC River
• Wikipedia River
• Twitter River
• RabbitMQ River
• ActiveMQ River
• RSS River
Quelques Rivers...
• CouchDB River
• MongoDB River
• JDBC River
• Wikipedia River
• Twitter River
• RabbitMQ River
• ActiveMQ River
• RSS River
• LDAP River
Quelques Rivers...
• CouchDB River
• MongoDB River
• JDBC River
• Wikipedia River
• Twitter River
• RabbitMQ River
• ActiveMQ River
• RSS River
• LDAP River
• FS River
Quelques Rivers...
• CouchDB River
• MongoDB River
• JDBC River
• Wikipedia River
• Twitter River
• RabbitMQ River
• ActiveMQ River
• RSS River
• LDAP River
• FS River
• Dropbox River
Quelques Rivers...
• CouchDB River
• MongoDB River
• JDBC River
• Wikipedia River
• Twitter River
• RabbitMQ River
• ActiveMQ River
• RSS River
• LDAP River
• FS River
• Dropbox River
• Dick Rivers
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 !)
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
Term Facet

D    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
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
Term Facet

D    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
Term Facet

D    Username          Date            Hashtag
1    dadoonet       2012-04-18
                            "facets" : {    1
                              "users" : { "terms" : {"field" : "username"} }
                           }
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
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
Date Histogram Facet

       Date      Hashtag
    2012-04-18     1
    2012-04-18     5
h   2012-04-18     2
    2012-04-18     2
    2012-04-18     6
h   2012-04-19     3
    2012-04-19     3
    2012-04-19     7
h   2012-04-20     4
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
h   2012-04-19     3
    2012-04-19     3
    2012-04-19     7
h   2012-04-20     4
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
Date Histogram Facet

       Date      Hashtag
    2012-04-18     1
    2012-04-18     5
h   2012-04-18     2
    2012-04-18     2
    2012-04-18     6
h   2012-04-19     3
    2012-04-19     3
    2012-04-19     7
h   2012-04-20     4
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
    2012-04-18     6
h   2012-04-19     3
    2012-04-19     3
    2012-04-19     7
h   2012-04-20     4
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
Range Facet

Hashtag
  1
  5
  2
  2
  6
  3
  3
  7
  4
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
Range Facet

Hashtag
  1
  5
  2
  2
  6
  3
  3
  7
  4
Range Facet
            "facets" : { "hashtags" : {
              "range" : { "field" : "hashtag",
              "ranges" : [
                 { "to" : 3 },
Hashtag          { "from" : 3, "to" : 5 },
                 { "from" : 5 }
              ] } } }
  1
  5
  2
  2
  6
  3
  3
  7
  4
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
                 } ] } }
Site marchand
Site marchand
Site marchand
Site marchand
Site marchand

      Ranges




      Term




      Term




     Ranges
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
Facettes
Cartographiques
Reprenons notre
  formulaire
Reprenons notre
  formulaire

           Recherche Full Text
Reprenons notre
  formulaire
Reprenons notre
  formulaire
Démonstration
Avez-vous fait du bruit ?
Architecture
Architecture
Architecture

          Twitter
         Streaming
            API
Architecture

          Twitter
         Streaming
            API
Architecture

                                    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"] }
   }
}'
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"] }
       }
    }'
Démonstration
http://onemilliontweetmap.com/
Architecture
Un peu plus de technique : partitions / réplications / scalabilité
Lexique
Lexique
• Nœud (node) : Une instance d'Elasticsearch (~ machine ?)
Lexique
• Nœud (node) : Une instance d'Elasticsearch (~ machine ?)
• Cluster : Un ensemble de nœuds
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
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
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.
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.
Créons un index


                    Cluster

           Nœud 1




                     Client
                     CURL
Créons un index


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

     }
                                                                 Shard 1
}'




                                     réplication non respectée
                                                                            Client
                                                                            CURL
Créons un index


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




                                       réplication respectée
                                                                          Client
                                                                          CURL
Réallocation dynamique


                       Cluster

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


   Shard 1   Shard 1
Réallocation dynamique


                       Cluster

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


   Shard 1   Shard 1
Réallocation dynamique


                       Cluster

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


   Shard 1   Shard 1
Réallocation dynamique


                       Cluster

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


   Shard 1   Shard 1
Réallocation dynamique


                       Cluster

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


   Shard 1   Shard 1
Réallocation dynamique


                       Cluster

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


   Shard 1   Shard 1
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
Réallocation dynamique


                           Cluster

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


                 Shard 1                        Shard 1




 Le tuning, c'est trouver le bon équilibre entre le
    nombre de nodes, shards et replicas !
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",
                                    ...
                               }'
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",
                                       ...
                                  }'
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",
                                       ...
                                  }'
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",
                                       ...
                                  }'
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",
                                     ...
                                }'
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",
                                     ...
                                }'
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",
                                     ...
                                }'
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",
                                     ...
                                }'
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",
                                     ...
                                }'
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
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
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
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
                                                                        2




                  Doc
          Doc      2
           1
                Client
                         $ curl localhost:9200/twitter/_search?q=elasticsearch
                CURL
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" : { ... }
                              } ]
                           }
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
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
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
Cherchons encore !

                                       Cluster

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




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

                                       Cluster

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




                  Client
                           $ curl localhost:9200/twitter/_search?q=elasticsearch
                  CURL
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
Cherchons encore !

                                   Cluster

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


                         Shard 1




                   Doc
            Doc     2
             1 Client
                         $ curl localhost:9200/twitter/_search?q=elasticsearch
                  CURL
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" : { ... }
                              } ]
                           }
La percolation
   Ou la recherche inversée
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 !
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
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" }
                }
            ]
        }
    }
}’
Usage du percolator
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 !" }
}'
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"
    ]
}
Tout doit être
  indexé ?
   Analyse et mapping
The lazy dog...
The lazy dog...

  The quick brown fox
jumped over the lazy Dog
The lazy dog...

  The quick brown fox
jumped over the lazy Dog

  The quick brown fox
jumped over the lazy dog
Analyseur standard
$ curl -XPOST 'localhost:9200/test/_analyze?analyzer=standard&pretty=1' -d
'The quick brown fox jumped over the lazy Dog'
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
    } ] }
Analyseur whitespace
$ curl -XPOST 'localhost:9200/test/_analyze?analyzer=whitespace&pretty=1' -d
'The quick brown fox jumped over the lazy Dog'
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", ...
    } ] }
Un analyseur


 Un ensemble
de tokenizers et
   de filtres
Un tokenizer

• Découpe une chaine en « mots » et
  transforme :
• whitespace tokenizer :
          "the dog!" -> "the", "dog!"
• standard tokenizer :
          "the dog!" -> "the", "dog"
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"
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"]
     }
    }
   }
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"
                }
            }
        }
    }
}
Les types
• string               • multi_field
• integer / long       • ip
• float / double        • geo_point
• boolean              • geo_shape
• null                 • binary
• array                • attachment (plugin)
• objects
Champs spéciaux

• _all (et include_in_all)
• _source
• _ttl
• parent / child
• nested
Autres fonctionnalités
• highlighting
• scoring
• sort
• explain
• multi get / multi search
• bulk
Démonstrations
 www.scrutmydocs.org
  CURL est ton ami !
JAVA est aussi ton ami !
Démonstrations
 www.scrutmydocs.org
  CURL est ton ami !
JAVA est aussi ton ami !
La communauté




~100 contributeurs directs au projet (+ de 2800 watchers et + de 470 forks)
La communauté




~100 contributeurs directs au projet (+ de 2800 watchers et + de 470 forks)
Elasticsearch - Montpellier JUG
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

Contenu connexe

PDF
Normandy JUG - Elasticsearch
PDF
Poitou charentes JUG - Elasticsearch
PDF
Nantes JUG - Elasticsearch
PDF
Finist JUG - Elasticsearch
PPTX
A la recherche d'ElasticSearch
PDF
Lausanne JUG - Elasticsearch
PDF
Elasticsearch - Esme sudria
PDF
Paris data geek - Elasticsearch
Normandy JUG - Elasticsearch
Poitou charentes JUG - Elasticsearch
Nantes JUG - Elasticsearch
Finist JUG - Elasticsearch
A la recherche d'ElasticSearch
Lausanne JUG - Elasticsearch
Elasticsearch - Esme sudria
Paris data geek - Elasticsearch

Tendances (20)

KEY
Elasticsearch - Devoxx France 2012
PDF
Migrer une application existante vers Elasticsearch - Nuxeo Tour 2014 - workshop
PDF
Présentation de ElasticSearch / Digital apéro du 12/11/2014
PDF
Breizhcamp 2015 - Comment (ne pas réussir à) modéliser ses data dans elastics...
KEY
Lyon JUG - Elasticsearch
KEY
Hands on lab Elasticsearch
PPTX
Tunis big data_meetup__21_nov2015__aymenzaafouri
KEY
Elasticsearch - OSDC France 2012
PDF
Oxalide Workshop #3 - Elasticearch, an overview
PPTX
ElasticSearch : Architecture et Développement
PDF
Moteurs de recherche : un oeil sous le capot avec Elastic Search
PDF
Introduction à ElasticSearch
PDF
Besoin de rien Envie de Search - Presentation Lucene Solr ElasticSearch
PDF
Tirer le meilleur de ses données avec ElasticSearch
PDF
[Breizhcamp 2015] MongoDB et Elastic, meilleurs ennemis ?
PPT
Solr and Elasticsearch in Action (at Breizhcamp)
PDF
Tout ce que le getting started mongo db ne vous dira pas
PPTX
Atelier : Développement rapide d&rsquo;une application basée surXWiki
PPTX
Jug algeria x wiki-atelier
PPTX
Webinaire 1 de la série Retour aux fondamentaux : Introduction à NoSQL
Elasticsearch - Devoxx France 2012
Migrer une application existante vers Elasticsearch - Nuxeo Tour 2014 - workshop
Présentation de ElasticSearch / Digital apéro du 12/11/2014
Breizhcamp 2015 - Comment (ne pas réussir à) modéliser ses data dans elastics...
Lyon JUG - Elasticsearch
Hands on lab Elasticsearch
Tunis big data_meetup__21_nov2015__aymenzaafouri
Elasticsearch - OSDC France 2012
Oxalide Workshop #3 - Elasticearch, an overview
ElasticSearch : Architecture et Développement
Moteurs de recherche : un oeil sous le capot avec Elastic Search
Introduction à ElasticSearch
Besoin de rien Envie de Search - Presentation Lucene Solr ElasticSearch
Tirer le meilleur de ses données avec ElasticSearch
[Breizhcamp 2015] MongoDB et Elastic, meilleurs ennemis ?
Solr and Elasticsearch in Action (at Breizhcamp)
Tout ce que le getting started mongo db ne vous dira pas
Atelier : Développement rapide d&rsquo;une application basée surXWiki
Jug algeria x wiki-atelier
Webinaire 1 de la série Retour aux fondamentaux : Introduction à NoSQL
Publicité

En vedette (19)

PPT
Chapitre3 elk concepts_avances
PDF
Découverte de Elastic search
PPTX
Séminaire Log Management
PPTX
Drupal 8 + Elasticsearch + Docker
PPT
Chapitre2 prise en_main_kibana
PDF
[Sildes] plateforme centralisée d’analyse des logs des frontaux http en temps...
PPTX
ElasticSearch Basic Introduction
PDF
Meetup Drupal Paris : Connexion Drupal et Elasticsearch
PPTX
Elasticsearch
PDF
Apache solr andré bois-crettez 08
PPT
Drupal and Elasticsearch
PDF
Simple fuzzy Name Matching in Elasticsearch - Graham Morehead
PPTX
Deck seo campus 2011 utiliser les logs serveurs
PPT
Chapitre1 elk chez_psa
PDF
Le PHP chez Deezer
PPTX
AFUP - Mini conférences PHP - Les LOGs
PDF
Cci octobre 2014
ODP
Elasticsearch presentation 1
PDF
Plateforme centralisée d’analyse des logs des frontaux http en temps réel dan...
Chapitre3 elk concepts_avances
Découverte de Elastic search
Séminaire Log Management
Drupal 8 + Elasticsearch + Docker
Chapitre2 prise en_main_kibana
[Sildes] plateforme centralisée d’analyse des logs des frontaux http en temps...
ElasticSearch Basic Introduction
Meetup Drupal Paris : Connexion Drupal et Elasticsearch
Elasticsearch
Apache solr andré bois-crettez 08
Drupal and Elasticsearch
Simple fuzzy Name Matching in Elasticsearch - Graham Morehead
Deck seo campus 2011 utiliser les logs serveurs
Chapitre1 elk chez_psa
Le PHP chez Deezer
AFUP - Mini conférences PHP - Les LOGs
Cci octobre 2014
Elasticsearch presentation 1
Plateforme centralisée d’analyse des logs des frontaux http en temps réel dan...
Publicité

Similaire à Elasticsearch - Montpellier JUG (20)

PDF
Oxalide Academy : Workshop #3 Elastic Search
KEY
Devoxx: Tribulation d'un développeur sur le Cloud
PDF
Nouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et mobilité
PDF
Nouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et Mobile
PDF
Tout ce que le getting started MongoDB ne vous dira pas
PDF
Construisez votre première application MongoDB
PPTX
Jean-Luc Boucho - Azure DocumentDB - Global Azure Bootcamp 2016 Paris
PPTX
[GAB2016] Azure DocumentDB - Jean-Luc Boucho
PDF
Développement d'un moteur de recherche avec Zend Search
PDF
Jabes 2011 - Ateliers "Sudoc, Calames, thèses.fr et le web de données"
PDF
Microservices-DDD-Telosys-Devoxx-FR-2022
PPTX
2014 04-09-fr - app dev series - session 4 - indexing
PDF
Grails from scratch to prod - MixIT 2011
PPTX
Javascript as a first programming language : votre IC prête pour la révolution !
PDF
NodeJs in real life
PPTX
Introduction à node.js
PDF
Enib cours c.a.i. web - séance #1 - html5 css3-js - 2
PDF
Devoxx 2014 : Atelier MongoDB - Decouverte de MongoDB 2.6
PDF
Hacking your home
PPTX
GraphTour - Workday: Tracking activity with Neo4j (French version)
Oxalide Academy : Workshop #3 Elastic Search
Devoxx: Tribulation d'un développeur sur le Cloud
Nouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et mobilité
Nouveau look pour une nouvelle vie : HTML5, Spring, NoSQL et Mobile
Tout ce que le getting started MongoDB ne vous dira pas
Construisez votre première application MongoDB
Jean-Luc Boucho - Azure DocumentDB - Global Azure Bootcamp 2016 Paris
[GAB2016] Azure DocumentDB - Jean-Luc Boucho
Développement d'un moteur de recherche avec Zend Search
Jabes 2011 - Ateliers "Sudoc, Calames, thèses.fr et le web de données"
Microservices-DDD-Telosys-Devoxx-FR-2022
2014 04-09-fr - app dev series - session 4 - indexing
Grails from scratch to prod - MixIT 2011
Javascript as a first programming language : votre IC prête pour la révolution !
NodeJs in real life
Introduction à node.js
Enib cours c.a.i. web - séance #1 - html5 css3-js - 2
Devoxx 2014 : Atelier MongoDB - Decouverte de MongoDB 2.6
Hacking your home
GraphTour - Workday: Tracking activity with Neo4j (French version)

Plus de David Pilato (9)

PDF
2018-10-02 - Un moteur de recherche NoSQL pour chercher^H^H^H^H^H^H^H^H trouv...
PDF
Managing your black friday logs Voxxed Luxembourg
PDF
Un moteur de recherche NoSQL pour chercher^H^H^H^H^H^H^H^H trouver...
PDF
Managing your Black Friday Logs NDC Oslo
PDF
Managing your black friday logs - Code Europe
PDF
Managing your black Friday logs - CloudConf.IT
PDF
Elasticsearch in 15 minutes
PDF
Elastify you application: from SQL to NoSQL in less than one hour!
KEY
Elasticsearch - Devoxx France 2012 - English version
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
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 - Code Europe
Managing your black Friday logs - CloudConf.IT
Elasticsearch in 15 minutes
Elastify you application: from SQL to NoSQL in less than one hour!
Elasticsearch - Devoxx France 2012 - English version

Dernier (7)

PDF
Tendances tech 2025 - SFEIR & WENVISION.pdf
PPTX
Presentation_Securite_Reseaux_Bac+2.pptx
PPTX
Souveraineté numérique - Définition et enjeux pour les entreprises et les dév...
PDF
FORMATION COMPLETE EN EXCEL DONE BY MR. NYONGA BRICE.pdf
PDF
FORMATION EN Programmation En Langage C.pdf
PDF
Modems expliqués- votre passerelle vers Internet.pdf
PDF
presentation_with_intro_compressee IEEE EPS France
Tendances tech 2025 - SFEIR & WENVISION.pdf
Presentation_Securite_Reseaux_Bac+2.pptx
Souveraineté numérique - Définition et enjeux pour les entreprises et les dév...
FORMATION COMPLETE EN EXCEL DONE BY MR. NYONGA BRICE.pdf
FORMATION EN Programmation En Langage C.pdf
Modems expliqués- votre passerelle vers Internet.pdf
presentation_with_intro_compressee IEEE EPS France

Elasticsearch - Montpellier JUG

  • 1. Elasticsearch. Le moteur de recherche élastique pour tous David Pilato, IDEO Technologies, Paris
  • 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" }
  • 3. 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" }
  • 5. Pour la démo Faites du bruit sur Twitter avec le hashtag #elasticsearch
  • 6. SQL Classique Cherche moi un document de décembre 2011 portant sur la france et contenant produit et david En SQL :
  • 7. 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%';
  • 8. 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 !
  • 9. Au final, on obtient • Autrement dit : tu as intérêt à savoir ce que tu cherches ! • Fouiller est interdit !
  • 10. 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 !
  • 13. Elasticsearch Your Data, your Search !
  • 14. 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 !
  • 15. 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, …
  • 16. 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" • Type : Regroupe des documents de même type • Index : Espace logique de stockage des documents dont les types sont fonctionnellement communs
  • 17. 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
  • 18. 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
  • 19. 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
  • 21. Interagir avec Elasticsearch • API REST : http://host:port/[index]/[type]/[_action/id] Méthodes HTTP : GET, POST, PUT, DELETE
  • 22. 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
  • 23. 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
  • 24. 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
  • 25. 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
  • 26. 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
  • 27. 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
  • 28. 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
  • 29. 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
  • 30. 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 !" } }'
  • 31. 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" }
  • 33. Chercher $ curl localhost:9200/twitter/tweet/_search?q=elasticsearch { "took" : 24, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 1, "max_score" : 0.227, "hits" : [ { "_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", […] } } ] } }
  • 34. 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, "max_score" : 0.227, "hits" : [ { "_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", […] } } ] } }
  • 35. Chercher $ curl localhost:9200/twitter/tweet/_search?q=elasticsearch { "took" : 24, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 1, "max_score" : 0.227, "hits" : [ { Coordonnées "_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", […] } } ] } }
  • 36. Chercher $ curl localhost:9200/twitter/tweet/_search?q=elasticsearch { "took" : 24, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 1, "max_score" : 0.227, "hits" : [ { "_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 } ] } }
  • 37. Chercher $ curl localhost:9200/twitter/tweet/_search?q=elasticsearch { "took" : 24, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 1, Document "max_score" : 0.227, "hits" : [ { 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", […] } } ] } }
  • 38. 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
  • 39. Query DSL • Requêtes précises : plutôt que de chercher « à la google », on peut utiliser des critères précis :
  • 40. 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" } } ] } }’
  • 41. Injecter les données Et au milieu coule une rivière
  • 43. La collecte Stockage Données
  • 44. La collecte Doc Stockage Données
  • 45. La collecte Stockage Données Doc
  • 46. La collecte Doc Stockage Données Doc
  • 47. La collecte Stockage Données Doc Doc
  • 48. La collecte Stockage Données Doc Doc
  • 49. La collecte Stockage Données Doc Doc
  • 50. La collecte Stockage Données Doc Doc
  • 51. La collecte Doc Stockage Données Doc Doc
  • 52. La collecte Stockage Données Doc Doc
  • 53. La collecte Stockage Données Doc Doc
  • 56. Quelques Rivers... • CouchDB River • MongoDB River
  • 57. Quelques Rivers... • CouchDB River • MongoDB River • JDBC River
  • 58. Quelques Rivers... • CouchDB River • MongoDB River • JDBC River • Wikipedia River
  • 59. Quelques Rivers... • CouchDB River • MongoDB River • JDBC River • Wikipedia River • Twitter River
  • 60. Quelques Rivers... • CouchDB River • MongoDB River • JDBC River • Wikipedia River • Twitter River • RabbitMQ River
  • 61. Quelques Rivers... • CouchDB River • MongoDB River • JDBC River • Wikipedia River • Twitter River • RabbitMQ River • ActiveMQ River
  • 62. Quelques Rivers... • CouchDB River • MongoDB River • JDBC River • Wikipedia River • Twitter River • RabbitMQ River • ActiveMQ River • RSS River
  • 63. Quelques Rivers... • CouchDB River • MongoDB River • JDBC River • Wikipedia River • Twitter River • RabbitMQ River • ActiveMQ River • RSS River • LDAP River
  • 64. Quelques Rivers... • CouchDB River • MongoDB River • JDBC River • Wikipedia River • Twitter River • RabbitMQ River • ActiveMQ River • RSS River • LDAP River • FS River
  • 65. Quelques Rivers... • CouchDB River • MongoDB River • JDBC River • Wikipedia River • Twitter River • RabbitMQ River • ActiveMQ River • RSS River • LDAP River • FS River • Dropbox River
  • 66. Quelques Rivers... • CouchDB River • MongoDB River • JDBC River • Wikipedia River • Twitter River • RabbitMQ River • ActiveMQ River • RSS River • LDAP River • FS River • Dropbox River • Dick Rivers
  • 67. 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 !)
  • 68. 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
  • 69. Term Facet D 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
  • 70. 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
  • 71. Term Facet D 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
  • 72. Term Facet D Username Date Hashtag 1 dadoonet 2012-04-18 "facets" : { 1 "users" : { "terms" : {"field" : "username"} } } 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
  • 73. 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
  • 74. Date Histogram Facet Date Hashtag 2012-04-18 1 2012-04-18 5 h 2012-04-18 2 2012-04-18 2 2012-04-18 6 h 2012-04-19 3 2012-04-19 3 2012-04-19 7 h 2012-04-20 4
  • 75. 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 h 2012-04-19 3 2012-04-19 3 2012-04-19 7 h 2012-04-20 4
  • 76. 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
  • 77. Date Histogram Facet Date Hashtag 2012-04-18 1 2012-04-18 5 h 2012-04-18 2 2012-04-18 2 2012-04-18 6 h 2012-04-19 3 2012-04-19 3 2012-04-19 7 h 2012-04-20 4
  • 78. 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 2012-04-18 6 h 2012-04-19 3 2012-04-19 3 2012-04-19 7 h 2012-04-20 4
  • 79. 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
  • 80. Range Facet Hashtag 1 5 2 2 6 3 3 7 4
  • 81. 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
  • 82. Range Facet Hashtag 1 5 2 2 6 3 3 7 4
  • 83. Range Facet "facets" : { "hashtags" : { "range" : { "field" : "hashtag", "ranges" : [ { "to" : 3 }, Hashtag { "from" : 3, "to" : 5 }, { "from" : 5 } ] } } } 1 5 2 2 6 3 3 7 4
  • 84. 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 } ] } }
  • 89. Site marchand Ranges Term Term Ranges
  • 90. 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
  • 92. Reprenons notre formulaire
  • 93. Reprenons notre formulaire Recherche Full Text
  • 94. Reprenons notre formulaire
  • 95. Reprenons notre formulaire
  • 99. Architecture Twitter Streaming API
  • 100. Architecture Twitter Streaming API
  • 101. Architecture 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"] } } }'
  • 102. 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"] } } }'
  • 104. Architecture Un peu plus de technique : partitions / réplications / scalabilité
  • 106. Lexique • Nœud (node) : Une instance d'Elasticsearch (~ machine ?)
  • 107. Lexique • Nœud (node) : Une instance d'Elasticsearch (~ machine ?) • Cluster : Un ensemble de nœuds
  • 108. 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
  • 109. 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
  • 110. 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.
  • 111. 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.
  • 112. Créons un index Cluster Nœud 1 Client CURL
  • 113. Créons un index $ curl -XPUT localhost:9200/twitter -d '{ Cluster "index" : { Nœud 1 "number_of_shards" : 2, "number_of_replicas" : 1 Shard 0 } Shard 1 }' réplication non respectée Client CURL
  • 114. Créons un index $ curl -XPUT localhost:9200/twitter -d '{ Cluster "index" : { Nœud 1 Nœud 2 "number_of_shards" : 2, "number_of_replicas" : 1 Shard 0 Shard 0 } }' Shard 1 Shard 1 réplication respectée Client CURL
  • 115. Réallocation dynamique Cluster Nœud 1 Nœud 2 Shard 0 Shard 0 Shard 1 Shard 1
  • 116. Réallocation dynamique Cluster Nœud 1 Nœud 2 Nœud 3 Shard 0 Shard 0 Shard 1 Shard 1
  • 117. Réallocation dynamique Cluster Nœud 1 Nœud 2 Nœud 3 Shard 0 Shard 0 Shard 0 Shard 1 Shard 1
  • 118. Réallocation dynamique Cluster Nœud 1 Nœud 2 Nœud 3 Shard 0 Shard 0 Shard 1 Shard 1
  • 119. Réallocation dynamique Cluster Nœud 1 Nœud 2 Nœud 3 Shard 0 Shard 0 Shard 1 Shard 1
  • 120. Réallocation dynamique Cluster Nœud 1 Nœud 2 Nœud 3 Nœud 4 Shard 0 Shard 0 Shard 1 Shard 1
  • 121. 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
  • 122. Réallocation dynamique Cluster Nœud 1 Nœud 2 Nœud 3 Nœud 4 Shard 0 Shard 0 Shard 1 Shard 1 Le tuning, c'est trouver le bon équilibre entre le nombre de nodes, shards et replicas !
  • 123. 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", ... }'
  • 124. 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", ... }'
  • 125. 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", ... }'
  • 126. 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", ... }'
  • 127. 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", ... }'
  • 128. 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", ... }'
  • 129. 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", ... }'
  • 130. 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", ... }'
  • 131. 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", ... }'
  • 132. 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
  • 133. 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
  • 134. 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
  • 135. 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 2 Doc Doc 2 1 Client $ curl localhost:9200/twitter/_search?q=elasticsearch CURL
  • 136. 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" : { ... } } ] }
  • 137. 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
  • 138. 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
  • 139. 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
  • 140. Cherchons encore ! Cluster Nœud 1 Nœud 2 Nœud 3 Doc Shard 0 1 Shard 0 Doc 1 Shard 1 Doc 2 Client $ curl localhost:9200/twitter/_search?q=elasticsearch CURL
  • 141. Cherchons encore ! Cluster Nœud 1 Nœud 2 Nœud 3 Doc Shard 0 1 Shard 0 Doc 1 Shard 1 Doc 2 Client $ curl localhost:9200/twitter/_search?q=elasticsearch CURL
  • 142. 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
  • 143. Cherchons encore ! Cluster Nœud 1 Nœud 2 Nœud 3 Doc Shard 0 1 Shard 0 Shard 1 Doc Doc 2 1 Client $ curl localhost:9200/twitter/_search?q=elasticsearch CURL
  • 144. 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" : { ... } } ] }
  • 145. La percolation Ou la recherche inversée
  • 146. 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 !
  • 147. 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
  • 148. 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" } } ] } } }’
  • 150. 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 !" } }'
  • 151. 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" ] }
  • 152. Tout doit être indexé ? Analyse et mapping
  • 154. The lazy dog... The quick brown fox jumped over the lazy Dog
  • 155. The lazy dog... The quick brown fox jumped over the lazy Dog The quick brown fox jumped over the lazy dog
  • 156. Analyseur standard $ curl -XPOST 'localhost:9200/test/_analyze?analyzer=standard&pretty=1' -d 'The quick brown fox jumped over the lazy Dog'
  • 157. 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 } ] }
  • 158. Analyseur whitespace $ curl -XPOST 'localhost:9200/test/_analyze?analyzer=whitespace&pretty=1' -d 'The quick brown fox jumped over the lazy Dog'
  • 159. 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", ... } ] }
  • 160. Un analyseur Un ensemble de tokenizers et de filtres
  • 161. Un tokenizer • Découpe une chaine en « mots » et transforme : • whitespace tokenizer : "the dog!" -> "the", "dog!" • standard tokenizer : "the dog!" -> "the", "dog"
  • 162. 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"
  • 163. 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"] } } }
  • 164. 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" } } } } }
  • 165. Les types • string • multi_field • integer / long • ip • float / double • geo_point • boolean • geo_shape • null • binary • array • attachment (plugin) • objects
  • 166. Champs spéciaux • _all (et include_in_all) • _source • _ttl • parent / child • nested
  • 167. Autres fonctionnalités • highlighting • scoring • sort • explain • multi get / multi search • bulk
  • 168. Démonstrations www.scrutmydocs.org CURL est ton ami ! JAVA est aussi ton ami !
  • 169. Démonstrations www.scrutmydocs.org CURL est ton ami ! JAVA est aussi ton ami !
  • 170. La communauté ~100 contributeurs directs au projet (+ de 2800 watchers et + de 470 forks)
  • 171. La communauté ~100 contributeurs directs au projet (+ de 2800 watchers et + de 470 forks)
  • 173. 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

Notes de l'éditeur