Elasticsearch 8实战:从全文搜索到向量检索
Elasticsearch 8: From Full-Text Search to Vector Retrieval
| iDev Tech | 2026-08-19T10:00:00
详解Elasticsearch 8的核心功能演进,重点介绍向量搜索(kNN)和混合检索的实战用法。
Detailed guide to Elasticsearch 8's evolution, focusing on vector search (kNN) and hybrid retrieval in practice.
全文搜索基础Elasticsearch的全文搜索基于倒排索引,支持分词(Analyzer)、相关性评分(BM25)和高亮显示。中文场景推荐IK分词器。关键查询类型:match(分词匹配)、term(精确匹配)、bool(组合查询)、range(范围查询)。向量搜索(kNN)ES 8原生支持dense_vector字段类型和kNN(k-Nearest Neighbors)搜索。将文本通过Embedding模型(如BERT、BGE)转为向量,存入ES后可进行语义相似度搜索。适合"找到意思相近的文档"而非"包含完全相同关键词的文档"。混合检索最佳实践是将传统BM25全文搜索和向量kNN搜索结合:先分别执行两种搜索,再通过RRF(Reciprocal Rank Fusion)算法融合排名。ES 8.8+内置了_search API的混合检索支持,一次请求同时执行两种检索并自动融合结果。
Full-Text Search BasicsElasticsearch's full-text search is built on inverted indexes, supporting tokenization (Analyzers), relevance scoring (BM25), and highlighting. For Chinese, the IK analyzer is recommended. Key query types: match (tokenized matching), term (exact match), bool (compound queries), range (range queries).Vector Search (kNN)ES 8 natively supports dense_vector field types and kNN (k-Nearest Neighbors) search. Convert text to vectors via embedding models (BERT, BGE), store in ES for semantic similarity search. Ideal for "find semantically similar documents" rather than "find documents with identical keywords."Hybrid RetrievalBest practice combines traditional BM25 full-text search with vector kNN search: execute both separately, then merge rankings via RRF (Reciprocal Rank Fusion). ES 8.8+ has built-in hybrid search support in the _search API, executing both retrieval types in a single request with automatic result fusion.