Search and beyond with Elasticsearch Florian Loretan Wunder Group - - PowerPoint PPT Presentation

search and beyond with elasticsearch
SMART_READER_LITE
LIVE PREVIEW

Search and beyond with Elasticsearch Florian Loretan Wunder Group - - PowerPoint PPT Presentation

Search and beyond with Elasticsearch Florian Loretan Wunder Group Horizons Track search Source: Flickr - Imad HADDAD Facets Frontend Search results Autocomplete Search queries Application Data manipulation Storage Indexing $ grep


slide-1
SLIDE 1
slide-2
SLIDE 2

Search and beyond with Elasticsearch

Florian Loretan – Wunder Group

Horizons Track

slide-3
SLIDE 3

search

slide-4
SLIDE 4
slide-5
SLIDE 5
slide-6
SLIDE 6
slide-7
SLIDE 7
slide-8
SLIDE 8
slide-9
SLIDE 9
slide-10
SLIDE 10

Source: Flickr - Imad HADDAD

slide-11
SLIDE 11

Search results Search queries Indexing

Frontend Application Storage

Facets Autocomplete Data manipulation

slide-12
SLIDE 12
slide-13
SLIDE 13
slide-14
SLIDE 14
slide-15
SLIDE 15
slide-16
SLIDE 16

$ grep search CHANGELOG.txt

slide-17
SLIDE 17

Drupal 8.0.0, 2015-11-19

  • * Added entity language variance support to search module.

* Search indexing and query preprocessors now get language information. Drupal 7.0, 2011-01-05

  • * Added support for language-aware searches.

Drupal 5.0, 2007-01-15

  • * Made it easy to investigate popular search terms.

Drupal 4.7.0, 2006-05-01

  • * Made indexer smarter and more robust.

* Added advanced search operators (phrase, node type, etc.). * Added customizable result ranking. Drupal 4.6.0, 2005-04-15

  • * Added UTF-8 support to make it work with all languages.

* Improved search indexing algorithm. * Improved search output. * Impose a throttle on indexing of large sites. * Added search block. Drupal 4.4.0, 2004-04-01

  • Improved the watchdog and search module to log search keys.

Drupal 4.2.0, 2003-08-01

  • * Changed the search module to use implicit AND'ing instead of implicit OR'ing.

Drupal 4.0.0, 2002-06-15

  • * Improved the search system by making it context sensitive.

* Added indexing. Drupal 2.0.0, 2001-03-15

  • Added "search infrastructure":

* Improved search page and integrated search functionality in the administration pages.

slide-18
SLIDE 18
slide-19
SLIDE 19
slide-20
SLIDE 20
slide-21
SLIDE 21
slide-22
SLIDE 22

+

slide-23
SLIDE 23
slide-24
SLIDE 24
  • 1. Fast
  • 2. Text analysis
  • 3. Facets
  • 4. Facets
  • 5. Facets
slide-25
SLIDE 25

Search API

slide-26
SLIDE 26
slide-27
SLIDE 27
  • 1. Abstraction of

Solr

  • 2. Configuration
  • 3. Hard to customize
slide-28
SLIDE 28
slide-29
SLIDE 29
slide-30
SLIDE 30

Real-Time Data How long can you wait for insights on your fast- moving data? With Elasticsearch, all data is immediately made available for search and analytics. Real-Time Advanced Analytics Combining the speed of search with the power of analytics changes your relationship with your data. Interactively search, discover, and analyze to gain insights that improve your products or streamline your business. Massively Distributed Elasticsearch allows you to start small and scale horizontally as you grow. Simply add more nodes, and let the cluster automatically take advantage of the extra hardware. Petabytes of data? Thousands of

slide-31
SLIDE 31

Developer-Friendly, RESTful API

slide-32
SLIDE 32

intranet

slide-33
SLIDE 33

simple

slide-34
SLIDE 34

search

slide-35
SLIDE 35

powerful

slide-36
SLIDE 36
slide-37
SLIDE 37

installation

slide-38
SLIDE 38

$ wget https://download.elastic.co/elasticsearch/release/org/ $ unzip elasticsearch-2.4.0.zip $ ./elasticsearch/bin/elasticsearch

slide-39
SLIDE 39

$ composer require elasticsearch/elasticsearch:~2.0

slide-40
SLIDE 40

indexing

slide-41
SLIDE 41

/**
 * Implements hook_entity_update().
 */
 function mymodule_entity_update(EntityInterface $entity) {
 
 $client = \Elasticsearch\ClientBuilder::fromConfig([
 'hosts' => $this->config->get('hosts'),
 ]);
 
 $client->index([
 'index' => 'content',
 'type' => 'article',
 'id' => $entity->id(),
 'body' => $entity,
 ]);
 }

slide-42
SLIDE 42
slide-43
SLIDE 43

Entity Save Serializer Elasticsearch

slide-44
SLIDE 44
slide-45
SLIDE 45

schema

slide-46
SLIDE 46

$client->indices()->putMapping([
 'index' => 'content',
 'type' => 'article',
 'body' => [
 'properties' => [
 'created' => [
 'type' => ‘date', 'format' => ‘epoch_second',
 ],
 'content' => [
 'type' => 'string',
 'analyzer' => 'english',
 ], 'image_url' => [
 'type' => 'string',
 'index' => ‘not_analyzed',
 ],
 ],
 ],
 ]);

slide-47
SLIDE 47

searching

slide-48
SLIDE 48

$result = $this->client->search([
 'index' => 'content,user',
 'body' => [
 'query' => [
 'multi_match' => [
 'query' => $input,
 'fields' => ['label^5', 'label.autocomplete'],
 'fuzziness' => 'AUTO',
 'prefix_length' => 1,
 ]
 ],
 ]
 ]);

slide-49
SLIDE 49

Ton Tony Tomi Jonny

slide-50
SLIDE 50
slide-51
SLIDE 51
slide-52
SLIDE 52
slide-53
SLIDE 53

$search_query = [
 'index' => 'content-' . $langcode,
 'type' => 'product',
 'size' => 0,
 'body' => [
 'query' => [
 // Search query goes here, same as before.
 ],
 'aggs' => [
 'suggested_terms' => [
 'terms' => [
 // Use the raw term to preserve the original case.
 'field' => 'suggestions.raw',
 'include' => [
 'pattern' => $input . '.*',
 'flags' => 'CANON_EQ|CASE_INSENSITIVE|UNICODE_CASE',
 ],
 'size' => 7,
 ],
 ],
 ],
 ],
 ];

slide-54
SLIDE 54

foreach ($result['aggregations']['suggested_terms']['buckets'] as $bucket) {
 $response[] = $bucket['key'];
 }

slide-55
SLIDE 55
slide-56
SLIDE 56

$search_query = [
 'body' => [
 'query' => [ 'bool' => [ 'must' => [ 'match' => [ 'content' => $input ], ], 'should' => [ 'term' => [ 'field_size' => ‘DIN A4' ], ], ],
 ],
 ],
 ];

slide-57
SLIDE 57
slide-58
SLIDE 58

https://en.wikipedia.org/wiki/Coffee_percolator

slide-59
SLIDE 59
slide-60
SLIDE 60

https://www.drupal.org/project/elasticsearch_helper

slide-61
SLIDE 61

/**
 * @ElasticsearchIndex(
 * id = "simple_node_index",
 * label = @Translation("Simple Node Index"),
 * indexName = "simple",
 * typeName = "node",
 * entityType = "node"
 * )
 */
 class SimpleNodeIndex extends ElasticsearchIndexBase {
 
 }

slide-62
SLIDE 62
slide-63
SLIDE 63

Search

Product Product Product

slide-64
SLIDE 64
slide-65
SLIDE 65
slide-66
SLIDE 66

Serializer Elasticsearch

slide-67
SLIDE 67
slide-68
SLIDE 68
slide-69
SLIDE 69
slide-70
SLIDE 70

websites search

slide-71
SLIDE 71

Summary

  • If search matters, the details matter
  • Elasticsearch has a really expressive API
  • Elasticsearch is fun to work with
slide-72
SLIDE 72

Thanks

Andreas Sahle David Park Fredrik Lassen Georg Oechsler Marcus Exner Marc Galang Mario Vercelloti Pieter De Troyer Vitalie Cracan Wouter Vanelslander Yannick Leyendecker Marcel Lambert

slide-73
SLIDE 73

Questions?

florian.loretan@wunder.io @floretan

slide-74
SLIDE 74

Evaluate This Session THANK YOU!

events.drupal.org/dublin2016/schedule

WHAT DID YOU THINK?