Elasticsearch ist eine verteilte Suchmaschine. Volltextsuche, Log-Analytics, Echtzeit-Aggregationen.
Indexierung¶
Create index¶
PUT /products { “mappings”: { “properties”: { “name”: { “type”: “text”, “analyzer”: “czech” }, “price”: { “type”: “float” }, “category”: { “type”: “keyword” } }}}
Index document¶
POST /products/_doc
Suche¶
Full-text search¶
GET /products/_search { “query”: { “bool”: { “must”: [{ “match”: { “name”: “notebook” } }], “filter”: [ { “range”: { “price”: { “lte”: 30000 } } }, { “term”: { “category”: “electronics” } } ] } }}
Aggregationen¶
GET /products/_search { “size”: 0, “aggs”: { “by_category”: { “terms”: { “field”: “category” }, “aggs”: { “avg_price”: { “avg”: { “field”: “price” } } } } }}
Wichtigste Erkenntnis¶
Elasticsearch für Volltextsuche und Analytics. Keyword für exakte Treffer, Text für Volltextsuche. Aggregationen für BI.