Elastic zero to hero

Elastic zero to hero

PHPERS Summit 2019 Poznań

6280bd845b84c195239417cdb33575c8?s=128

K.Skaradziński

September 04, 2019
Tweet

Transcript

  1. ZERO TO HERO ELASTIC

  2. CONFIGURATION ▸ 1. https://github.com/skowron-line/phpers2019-workshop ▸ 2. docker-compose up -d

  3. DOCKER-COMPOSE PS

  4. HTTP://LOCALHOST:9200

  5. HTTP://LOCALHOST:5601

  6. SQL VS ELASTIC Elastic SQL Field Column Document Row Index

    Table Database Cluster
  7. CREATE INDEX PUT {index}

  8. ADD DOCUMENT POST {index}/_doc

  9. SAMPLE RESPONSE { "_index" : "test", "_type" : "_doc", "_id"

    : "H9wYAG0Bjhby-D6cxV_8", "_version" : 1, "result" : "created", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 0, "_primary_term" : 1 }
  10. UPDATE DOCUMENT PUT {index}/_doc/{id}

  11. SAMPLE RESPONSE { "_index" : "test", "_type" : "_doc", "_id"

    : "H9wYAG0Bjhby-D6cxV_8", "_version" : 2, "result" : "updated", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 0, "_primary_term" : 1 }
  12. DELETE DOCUMENT DELETE {index}/_doc

  13. SAMPLE RESPONSE { "_index" : "test", "_type" : "_doc", "_id"

    : "H9wYAG0Bjhby-D6cxV_8", "_version" : 2, "result" : "deleted", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 0, "_primary_term" : 1 }
  14. While using the _version might seem to work in certain

    cases, I would recommend to never use it for anything else than optimistic locking of updates. In particular, versions do not carry any meaning: they might look like the number of times a document has been modified but it is not always the case (for instance if you create a new document which has the same ID as a document that you just deleted, the version number of the new document will not be 1), and more importantly it is an implementation detail, this behaviour might change in the future. Versioning
  15. BULK curl -X POST "localhost:9200/_bulk" -H 'Content-Type: application/json' -d' {

    "create" : { "_index" : "test", "_id" : "1" } } {“field”: “value”, “field”: “value”} { "delete" : { "_index" : "test", "_id" : "1" } } { "update" : {"_id" : "1", "_index" : "test"} } { "doc" : {"field2" : "value2"} }
  16. ANALYSING PROCESS Text -> Char filter -> Tokenizer -> Token

    filter -> Inverted index
  17. CHAR FILTER The character filter has the ability to perform

    addition, removal or replacement actions on the input text given to them.
  18. CHAR FILTER “<b>Phpers Summit</b>” “Phpers summit”

  19. TOKENIZER A tokenizer receives a stream of characters, breaks it

    up into individual tokens (usually individual words), and outputs a stream of tokens
  20. TOKENIZER “Phpers summit najlepsza konferencja w Polsce” “Phpers”, “summit”, “najlepsza”,

    “konferencja”, “w”, “Polsce”
  21. TOKEN FILTER Token filters can act on the tokens generated

    from the tokenizers and modify, add or remove them
  22. ANALYZER Analyzer is combination of tokenizer and token filters

  23. BUILD IN ANALYZERS ‣ standard (default) combination of (standard token

    filter, lowercase and stop token filter) ‣ simple ‣ whitespace ‣ stop ‣ keyword ‣ pattern ‣ language ‣ fingerprint
  24. NORMALIZER Normalizers are similar to analyzers except that they may

    only emit a single token
  25. INVERTED INDEX Frontend developer w Warszawie PHP Developer Poznań

  26. INVERTED INDEX Token Document 1 Document 2 frontend 1 php

    1 developer 1 1 poznan 1 warszawa 1
  27. MAPPING Mapping is the process of defining how a document,

    and the fields it contains, are stored and indexed. For instance, use mappings to define: ‣ which string fields should be treated as full text fields. ‣ which fields contain numbers, dates, or geolocations. ‣ the format of date values. ‣ custom rules to control the mapping for dynamically added fields.
  28. MAPPING "mappings": { "properties": { "age": { "type": "integer" },

    "email": { "type": "keyword" }, "name": { "type": "text" } } }
  29. MAPPING PUT {index} { "mappings": { "properties": { "age": {

    "type": "integer" }, ... } } }
  30. DYNAMIC MAPPING { "mappings": { "dynamic_date_formats": ["MM/dd/yyyy"] } }

  31. DYNAMIC MAPPING TEMPLATES "dynamic_templates": [ { "strings": { "match_mapping_type": "string",

    "mapping": { "type": "text", "analyzer": "whitespace" } } } ]
  32. BASIC QUERIES ‣ Match ‣ Multi_match ‣ Term / terms

    ‣ Range ‣ Wildcard ‣ Query_string ‣ Function_score ‣ Script_score
  33. BOOL QUERIES and, or / must, should

  34. BOOL QUERIES title = "php developer" AND city = "warszawa"

    { "query": { "must": [ { "term": { "title": { "value": "php developer" } } }, { "term": { "city": { "value": "warszawa" } } } ] } }
  35. LETS GO!