Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Tus primeros pasos con Elasticsearch

Tus primeros pasos con Elasticsearch

David Padilla

July 07, 2015
Tweet

More Decks by David Padilla

Other Decks in Programming

Transcript

  1. SELECT * FROM properties INNER JOIN tasks ON tasks.property_id =

    properties.id WHERE bedrooms = 2 AND bathrooms = 3 AND tasks.pending = true;
  2. SELECT * FROM properties INNER JOIN tasks ON tasks.property_id =

    properties.id WHERE bedrooms = 2 AND bathrooms = 3 AND tasks.pending = true AND name LIKE ('%query%');
  3. SELECT * FROM properties INNER JOIN tasks ON tasks.property_id =

    properties.id LEFT JOIN addresses ON addresses.id = property.id WHERE bedrooms = 2 AND bathrooms = 3 AND tasks.pending = true AND (name LIKE ('%query%') OR address.street LIKE('%query%') OR address.state LIKE ('%query%'));
  4. POST sistemix/contacto { nombre: "Omaro Cancellara", edad: 30, intereses: ["angular",

    "rails"] } POST sistemix/contacto { nombre: "Alvaro Pereyra", edad: 25, intereses: ["node", "rails"] } POST sistemix/contacto { nombre: "Gloria Palma", edad: 20, intereses: ["angular", "cloud"] }
  5. hits: { { nombre: "Daniel Pliego", edad: 25, intereses: ["diseño"]

    } ,{ nombre: "Alvaro Pereyra", edad: 25, intereses: ["node", "rails"] } }
  6. hits: { { nombre: "Omaro Cancellara", edad: 30, intereses: ["angular",

    "rails"] }, { nombre: "Alvaro Pereyra", edad: 25, intereses: ["node", "rails"] } }
  7. SELECT * FROM contacts INNER JOIN interests ON contact.id =

    interest.id WHERE interest.name = "rails";
  8. Índice Invertido 1 2 3 4 5 6 7 daniel

    x pliego x omaro x cancellara x gloria x palma x alvaro x pereyra x
  9. Char filter El hierro es el amigo más honesto que

    puedes tener El hierro es el amigo mas honesto que puedes tener
  10. Tokenize El hierro es el amigo mas honesto que puedes

    tener el hierro es el amigo mas honesto que puedes tener
  11. Token Filter El hierro es el amigo mas honesto que

    puedes tener hierro amigo honesto puedes tener
  12. Poor man’s full text search WHERE nombre LIKE “oma*” WHERE

    nombre LIKE “dan*” WHERE nombre LIKE “*plie*”
  13. Índice Invertido 1 2 dan x dani x daniel x

    ani x anie x aniel x nie x niel x
  14. aggregations GET sistemix/contacto/_search { query: { term: { intereses: "rails"

    } }, aggregations: { edades: { terms: { field: "edad" } } } }
  15. { nombre: "Omaro Cancellara", edad: 30, intereses: ["angular", "rails"] }

    },{ nombre: "Alvaro Pereyra", edad: 25, intereses: ["node", "rails"] } } }]}, "aggregations":{ "edades":{ "_type":"terms","missing":0,"total":2,"other":0, "terms": [ {"term":25,"count":1}, {"term":30,"count":1} ] } } }
  16. aggregations GET sistemix/contacto/_search { query: { term: { intereses: "rails"

    } }, aggregations: { edades_promedio: { avg: { field: "edad" } } } }
  17. { nombre: "Omaro Cancellara", edad: 30, intereses: ["angular", "rails"] }

    },{ nombre: "Alvaro Pereyra", edad: 25, intereses: ["node", "rails"] } } }]}, "aggregations":{ “edades_promedio”:{ { “value”: 27.5 } } }
  18. geo distance { "filtered" : { "query" : { "match_all"

    : {} }, "filter" : { "geo_distance" : { "distance" : "200km", "pin.location" : { "lat" : 40, "lon" : -70 } } } } }
  19. { "filtered" : { "query" : { "match_all" : {}

    }, "filter" : { "geo_bounding_box" : { "pin.location" : { "top_left" : { "lat" : 40.73, "lon" : -74.1 }, "bottom_right" : { "lat" : 40.01, "lon" : -71.12 } } } } } } geo bounding box
  20. geo polygon { "filtered" : { "query" : { "match_all"

    : {} }, "filter" : { "geo_polygon" : { "person.location" : { "points" : [ {"lat" : 40, "lon" : -70}, {"lat" : 30, "lon" : -80}, {"lat" : 20, "lon" : -90} ] } } } } }
  21. ##################### Elasticsearch Configuration Example ##################### # This file contains an

    overview of various configuration settings, # targeted at operations staff. Application developers should # consult the guide at <http://elasticsearch.org/guide>. # # The installation procedure is covered at # <http://elasticsearch.org/guide/en/elasticsearch/reference/current/setup.html>. # # Elasticsearch comes with reasonable defaults for most settings, # so you can try it out without bothering with configuration. # # Most of the time, these defaults are just fine for running a production # cluster. If you're fine-tuning your cluster, or wondering about the # effect of certain configuration option, please _do ask_ on the # mailing list or IRC channel [http://elasticsearch.org/community]. # Any element in the configuration can be replaced with environment variables # by placing them in ${...} notation. For example: # #node.rack: ${RACK_ENV_VAR} # For information on supported formats and syntax for the config file, see # <http://elasticsearch.org/guide/en/elasticsearch/reference/current/setup-configuration.html> ################################### Cluster ################################### # Cluster name identifies your cluster for auto-discovery. If you're running # multiple clusters on the same network, make sure you're using unique names. # cluster.name: julian #################################### Node ##################################### # Node names are generated dynamically on startup, so you're relieved # from configuring them manually. You can tie this node to a specific name: # node.name: "Luna"