Alexander Girke
Universität Leipzig / Mercateo Gruppe
Aufbau
Suchen
Weitere Features
Beispiel: Kunde/Kundin sucht ein T-Shirt
früher: Kataloge aus Papier
https://www.tagesspiegel.de/wirtschaft/versandhandel-otto-katalog-wird-eingestellt/22771476.html
20 Millionen Artikel,
⌀ 10 Artikeln pro Seite
= 2 Millionen Seiten
2 Millionen Seiten,
0,15mm pro Seite
= 300000mm
= 300m Höhe
https://commons.wikimedia.org/wiki/File:Margaret_Hamilton_-_restoration.jpg
Wie findet man da effizient ein blaues T-Shirt, das maximal 15€ kostet?
Mercateo Deutschland Sortiment:
20 Millionen Artikel
Suchmaschinen
Gibt's da schon was Fertiges?
Wie funktioniert das?
Wozu braucht man das?
Wozu man Suchmaschinen braucht ...
... beispielsweise zur Volltextsuche ...
... also "Finde für meinen Text x alle Dokumente, die diesen enthalten ...
... und sage mir, wie gut ein Dokument zu meiner Suche passt."
Wie Suchmaschinen funktionieren ...
... beispielsweise mit Inversen Indexstrukturen
... also ein Verzeichnis aller Vorkommen von Schlüsselbegriffen
... Beispiel:
... Scoring beispielsweise durch tf-idf
(= term frequency - inverse document frequency)
... Stoppwörter werden ausgelassen
Was es schon gibt ...
... besonders beliebt: Apache Lucene
... Server basierend auf Lucene: Solr & ElasticSearch
Vorteile:
ElasticSearch
https://www.elastic.co/static/images/elk/elk-stack-elkb-diagram.svg
https://images.contentstack.io/v3/assets/bltefdd0b53724fa2ce/blt4b5878e620695c17/5c11edeb928f832d782d0622/elk-stack-elk-bee.svg
ElasticSearch Cluster
Index 1
Index n
...
Shard 1
Shard 2
= Rechner
Knoten 1
Replica Shard 2
Knoten 2
Replica Shard 1
Shard x
= Lucene-Index
GET /articleindex/article/_search?q=tshirt
Index
Operation
Typ
Term
POST /articleindex/article/1
{ ... }
GET /articleindex/_mapping
Suchen
Dokument anlegen
Mapping anzeigen
POST /articleindex/_bulk
{ ... }
{ ... }
Mehrere Dokumente mit einem Mal anlegen
{
"id": ...,
"title": ...,
"description": ...,
"manufacturerName": ...,
"image": {
"mimeType": ...,
"href": ...
},
"keywords": [ ... ],
"color": ...,
"price": {
"amount": ...,
"currency": ...,
"tax": ...
}
}
{
"articleindex": {
"mappings": {
"article": {
"properties": {
"description": {
"type": "text"
},
"id": {
"type": "text"
},
"image": {
"properties": {
"href": {
"type": "text"
},
"mimeType": {
"type": "text"
}
}
},
"keywords": {
"type": "text"
},
"manufacturerName": {
"type": "text"
},
"price": {
"properties": {
"amount": {
"type": "float"
},
"currency": {
"type": "text"
},
"tax": {
"type": "float"
}
}
},
"title": {
"type": "text"
}
}
}
}
}
}
POST /articleindex/article/_search
{
"query": {
"match_all": {}
}
}
Match All Query
POST /articleindex/article/_search
{
"query": {
"match": {
"_all": "Lorem ipsum dolor"
}
}
}
Match Query (Volltext-Query)
POST /articleindex/article/_search
{
"query": {
"term": {
"manufacturerName": "Super Manufacturer"
}
}
}
Term Query
POST /articleindex/article/_search
{
"query": {
"prefix" : { "title" : "shir" }
}
}
Prefix Query
POST /articleindex/article/_search
{
"query": {
"bool" : {
"must" : {
"term" : { "image.mimeType" : "image/jpeg" }
},
"filter": {
"term" : { "manufacturerName" : "Super Manufacturer" }
},
"should" : [
{
"match" : { "title" : "Shirt" }
}
]
}
}
}
Bool Query
(Compound Query)
{
"id": ...,
"title": ...,
"variations": [
{
"color": "blue",
"size": "L"
},
{
"color": "red",
"size": "M"
}
]
}
{ "article" : {
"properties" : {
"variations" : {
"type" : "nested",
"properties": {
"color": { "type": "keyword" },
"size": { "type": "keyword" }
}}}}}
Nested Property
(Index Definition)
{
"id": ...,
"title": ...,
"variations": [
{
"color": "blue",
"size": "M"
}
]
}
blau & M
POST /articleindex/article/_search
{
"query": {
"nested" : {
"path" : "article",
"query" : {
"bool" : {
"must" : [
{
"match" : {"article.variations.color" : "blue"}
},
{
"match" : {"article.variations.size" : "M"}
}
]
}
}
}
}
}
Nested Query
(Joining Query)
findet alle Dokumente, bei denen blau & M in einem Subdokument sind
Live Demo
Performance erhöhen
Fazit
Fragen?