Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

$ cat .profile GIT_AUTHOR_NAME=Florian Gilcher [email protected] TM_COMPANY=Asquera GmbH TWITTER_HANDLE=argorak GITHUB_HANDLE=skade

Slide 3

Slide 3 text

• Backend developer • Focused on infrastructure and databases

Slide 4

Slide 4 text

• Elasticsearch Usergroup • mrgn.in meetup • Rust Usergroup (co-org) • organizer alumni eurucamp • organizer alumni JRubyConf.EU • Ruby Berlin board member

Slide 5

Slide 5 text

Adequate Full Text Search

Slide 6

Slide 6 text

The evaluation problem

Slide 7

Slide 7 text

Given almost no time and an unknown problem space, how do I evaluate "fitness for purpose"?

Slide 8

Slide 8 text

You can't

Slide 9

Slide 9 text

Given almost no time and only a glimpse of the problem space, how do I evaluate "fitness for purpose"?

Slide 10

Slide 10 text

How much of a glimpse do I need?

Slide 11

Slide 11 text

In this talk, I’ll present: • a solution unfit for purpose • a solution fit for purpose, but only in cer- tain boundaries • a comparison to a fully fledged solution

Slide 12

Slide 12 text

To the daily practitioners: I’ll gloss over a lot of points.

Slide 13

Slide 13 text

• Elasticsearch • PostgreSQL • MongoDB

Slide 14

Slide 14 text

Issue 1 Search systems are not binary. Faults in the system degrade the quality of the system, rarely break it.

Slide 15

Slide 15 text

Issue 2 Full text searchers are far more focused on inputs then on output.

Slide 16

Slide 16 text

Building Block 1 An inverted index

Slide 17

Slide 17 text

doc id content 0 "Überlin ist auf Twitter" 1 "Ich bin auf Twitter" 2 "Ich folge Überlin"

Slide 18

Slide 18 text

terms document ids uberlin 0,2 twitter 0,1 bin 1 ich 1,2 auf 0,1

Slide 19

Slide 19 text

Initial search rules are easy: if one or more of the terms to the left is searched for, find the document that matches. Count the matches.

Slide 20

Slide 20 text

Building Block 2 Textual input

Slide 21

Slide 21 text

Full text searchers generally work on real world text. Get hold of as many samples as possible. If necessary, write some on your own.

Slide 22

Slide 22 text

Don’t use an random generator. Or spend your next weeks writing a sophisticated one.

Slide 23

Slide 23 text

Your system should bring capabilities handling real world text.

Slide 24

Slide 24 text

Analysis

Slide 25

Slide 25 text

Analysis determines which terms end up at the left side of the table in the first place.

Slide 26

Slide 26 text

analysis result "ich folge Überlin" whitespace "ich" "folge" "Überlin" lowercase "ich" "folge" "überlin" normalize "ich" "folge" "uberlin" stemming "ich" "folg" "uberlin"

Slide 27

Slide 27 text

analysis result "ich folge ueberlin" whitespace "ich" "folge" "ueberlin" lowercase "ich" "folge" "ueberlin" normalize "ich" "folge" "ueberlin" stemming "ich" "folg" "uberlin"

Slide 28

Slide 28 text

This step happens both on indexing and queries.

Slide 29

Slide 29 text

Manipulating analysis is the basis for manipulating matches.

Slide 30

Slide 30 text

Can I manipulate analysis?

Slide 31

Slide 31 text

MongoDB Only choose between language presets PostgreSQL Analysis happens through normal PL/SQL functions Elasticsearch Analyser configura- tion with a wide vari- ety of choice

Slide 32

Slide 32 text

Ü

Slide 33

Slide 33 text

Does your system comfortably speak Unicode?

Slide 34

Slide 34 text

doc id field value 1 Test 2 test 3 Überlin

Slide 35

Slide 35 text

token doc ids test 1,2 uberlin 3

Slide 36

Slide 36 text

MongoDB

Slide 37

Slide 37 text

search term no. matches Test 2 test 2 Überlin 1 überlin 0

Slide 38

Slide 38 text

token doc ids test 1,2 Überlin 3

Slide 39

Slide 39 text

input result überlin überlin Überlin Überlin

Slide 40

Slide 40 text

MongoDB fails at the simplest case, lowercasing german umlauts, in german settings.

Slide 41

Slide 41 text

The exact analysis behaviour is not user-controllable, for simplicities sake.

Slide 42

Slide 42 text

The suggestion is to preprocess yourself.

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Further down the Unicode

Slide 45

Slide 45 text

How well does you system handle "creative" codes?

Slide 46

Slide 46 text

"\u0055\u0308" "\u0075\u0308"

Slide 47

Slide 47 text

"\u0055\u0308" #=> Ü "\u0075\u0308" #=> ü

Slide 48

Slide 48 text

PostgreSQL

Slide 49

Slide 49 text

postgres=# SELECT unaccent(U&’\0075\0308’); unaccent ———- ü (1 row)

Slide 50

Slide 50 text

PostgreSQL handles UCS-2 level 1, not UTF.

Slide 51

Slide 51 text

No combining chars.

Slide 52

Slide 52 text

“ we should really reject combining chars, but can’t do that w/o breaking BC.”

Slide 53

Slide 53 text

sigh, Software

Slide 54

Slide 54 text

If you use PostgreSQL and text manipulation, you probably have a bug in the hiding there.

Slide 55

Slide 55 text

UCS-2 for all textual data is a doable constraint, though.

Slide 56

Slide 56 text

input result überlin überlin Überlin überlin \u0055 \u0308 Invalid input \u0075 \u0308 Invalid input

Slide 57

Slide 57 text

Elasticsearch

Slide 58

Slide 58 text

Elasticsearch can handle all those cases and then some, using the analysis-icu plugin.

Slide 59

Slide 59 text

Install it and use it.

Slide 60

Slide 60 text

curl -XGET ’localhost:9200/_analyze?\ tokenizer=\ icu_tokenizer\ &token_filters=\ icu_folding,icu_normalizer’\ -d ’Überlin’

Slide 61

Slide 61 text

input result überlin uberlin Überlin uberlin \u0055 \u0308 uberlin \u0075 \u0308 uberlin

Slide 62

Slide 62 text

The way the system supports you in safely inserting textual input is of paramount importance!

Slide 63

Slide 63 text

Find the worst shenanegans of you language, try it out.

Slide 64

Slide 64 text

l’elision, c’est magnifique

Slide 65

Slide 65 text

Building Block 3 Scoring

Slide 66

Slide 66 text

Search is all about relevance and combinations thereof.

Slide 67

Slide 67 text

Was the match in the title or the body of a document?

Slide 68

Slide 68 text

How many options do I have?

Slide 69

Slide 69 text

All three systems can weight matches on fields differently.

Slide 70

Slide 70 text

When can I decide those weights?

Slide 71

Slide 71 text

database index time query time MongoDB yes no PostgreSQL yes no Elasticsearch yes yes

Slide 72

Slide 72 text

Weights during index time need a rebuild of the index every time you change them.

Slide 73

Slide 73 text

If in doubt, choose query time weights.

Slide 74

Slide 74 text

Can I influence the scoring/ranking further?

Slide 75

Slide 75 text

database MongoDB no PostgreSQL yes, using PL/SQL functions Elasticsearch yes, in many fashions (geo, distance, etc.)

Slide 76

Slide 76 text

Building Block 4 Documentation

Slide 77

Slide 77 text

I glossed over a lot of details.

Slide 78

Slide 78 text

How well is the process documented, internally and interface-wise?

Slide 79

Slide 79 text

database interface internal MongoDB good almost non-existent PostgreSQL great great Elasticsearch great great

Slide 80

Slide 80 text

Can I grow beyond?

Slide 81

Slide 81 text

And this is where the fun starts and we stop.

Slide 82

Slide 82 text

What’s adequate?

Slide 83

Slide 83 text

• Allows to manipulate analysis • Assists with real world input • Allows you to build combined, extensible queries • Good documentation

Slide 84

Slide 84 text

MongoDB is not fit for purpose with holes that can only be fixed by careful preparation of that data.

Slide 85

Slide 85 text

That preparation needs lots of detail knowledge you probably don’t want to aquire.

Slide 86

Slide 86 text

PostgreSQL is adequate and in the PostgreSQL tradition of stable, well-documented features. It doesn’t win prices, but is workable and reliable.

Slide 87

Slide 87 text

A good solution if search is just a bystander. A thousand times better than LIKE.

Slide 88

Slide 88 text

Elasticsearch is based on Lucene and comes with all the goodies and also has great documentations and guides.

Slide 89

Slide 89 text

If search is at the core of your product, use a proper search engine.

Slide 90

Slide 90 text

References on the meetup group tomorrow.

Slide 91

Slide 91 text

Thank you!

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

COURSES

Slide 94

Slide 94 text

Elasticsearch for managers: http://esmanagers2014.asquera.de/

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

December 2nd

Slide 97

Slide 97 text

Getting started workshop: http://purchases.elastic- search.com/class/elasticsearch/elk-work- shop/berlin-germany/2014-12-15

Slide 98

Slide 98 text

No content

Slide 99

Slide 99 text

December 15th