Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Elasticsearch

Giới thiệu

Elasticsearch là search engine phân tán, được xây dựng trên Apache Lucene. Nó cung cấp khả năng tìm kiếm full-text, phân tích log, và lưu trữ dữ liệu ở dạng JSON document.

┌──────────────────────────────────────────────────────────────┐
│                    Elasticsearch Cluster                     │
│                                                              │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐         │
│  │   Node 1    │  │   Node 2    │  │   Node 3    │         │
│  │  (Master)   │  │  (Data)     │  │  (Data)     │         │
│  │             │  │             │  │             │         │
│  │  Shard 1P   │  │  Shard 1R   │  │  Shard 2P   │         │
│  │  Shard 2R   │  │  Shard 2P   │  │  Shard 1R   │         │
│  └─────────────┘  └─────────────┘  └─────────────┘         │
│                                                              │
│  P = Primary Shard,  R = Replica Shard                      │
└──────────────────────────────────────────────────────────────┘

Stack

Tài liệu này sử dụng Elastic.Clients.Elasticsearch - .NET client chính thức cho Elasticsearch 8+.

dotnet add package Elastic.Clients.Elasticsearch

Mục lục

#Chủ đềMô tả
1Concepts Cơ bản & Kết nốiIndex, Shard, Replica, DI setup trong ASP.NET Core
2Mapping & Field TypesAttribute mapping, Fluent mapping, text vs keyword, nested
3Indexing DocumentsCRUD, Bulk API, Upsert, Ingest Pipeline qua .NET
4Basic SearchMatch, Term, Range, Bool query, Sorting qua .NET
5Query DSL Nâng caoMulti-match, Fuzzy, Nested, Highlight, Scroll
6AggregationsMetric, Terms, Range, Date Histogram, Faceted Search
7Analyzers & TokenizersBuilt-in analyzers, Custom analyzer, Autocomplete
8Performance TuningFilter vs must, Source filtering, Search After, ILM
9Cluster ManagementHealth check, ILM, Alias, Snapshot, ASP.NET Core integration

Use Cases

Use CasePhù hợp
Full-text search✅ Mạnh nhất
Log analytics (ELK Stack)✅ Phổ biến
Application search
Geospatial search
Real-time analytics
Primary database❌ Không phù hợp
Transactional data❌ Không phù hợp