RousselTMLEARNING

Article · Elasticsearch: from discovery to expertise

Vector search and RAG

1. Vectors and kNN #

Searching by meaning.

Mapping and query #

PUT docs
{ "mappings": { "properties": {
    "title":   { "type": "text", "analyzer": "french" },
    "content": { "type": "text", "analyzer": "french" },
    "content_vector": { "type": "dense_vector", "dims": 384, "index": true, "similarity": "cosine" } } } }

GET docs/_search
{ "knn": { "field": "content_vector", "query_vector": [0.12, -0.03, "..."], "k": 10, "num_candidates": 100 },
  "_source": [ "title" ] }

Embeddings are computed by a model (in your application, or in Elasticsearch via the inference API and the semantic_text type, which handles chunking and vectorization automatically).

2. Hybrid search #

The best of both.

RRF #

BM25 + kNN hybrid search merged with RRF
GET docs/_search
{
  "retriever": { "rrf": {
    "retrievers": [
      { "standard": { "query": { "match": { "content": "réinitialiser le mot de passe" } } } },
      { "knn": { "field": "content_vector", "query_vector": [0.12, -0.03, "..."], "k": 20, "num_candidates": 100 } }
    ],
    "rank_window_size": 50
  } },
  "size": 5
}
  • BM25 excels on exact terms (error codes, product names); vector search on rephrasings.
  • Reciprocal Rank Fusion combines rankings without having to calibrate incomparable scores.
  • For RAG, the 3 to 5 best passages are sent to the LLM with the question, citing their sources.
Good to know: Some features depend on the version and the license level (Basic, Platinum, Enterprise): check them in the documentation and on the Elastic subscriptions page before using them in production.

📄 Vector search and RAG with Elasticsearch: dense_vector, kNN, hybrid search and RRF →

My progress

  • ⏱ Estimated time : ≈ 4 min

Sign in to track your progress and take notes. Sign in

⭐ Rate this lesson

5.0 initial rating from the teaching team

Sign in to rate this lesson →

💬 Recent discussions about this course

Ask a question about this lesson →See all discussions about this course

Course Glossary

RBAC (Role-Based Access Control)

An access control method where permissions are assigned to specific roles (e.g., admin, reader) rather than directly to individual users.

Authentication

The process of verifying the identity of a user or system (e.g., login/password, tokens, biometrics).

Authorization

The process that occurs after authentication to determine if the entity has the necessary rights and privileges to access a resource.

API Key

A unique alphanumeric code used to identify, authenticate, and authorize access to an Application Programming Interface (API).

Architecture

The overall structural design of an IT system, defining its various components, their relationships, and the principles guiding its evolution.

Repository

A centralized storage location. This can refer to a source code repository (e.g., Git) or an artifact and binary repository (e.g., Harbor, Nexus, Arti...

Elasticsearch

A distributed, RESTful search and analytics engine capable of addressing a growing number of use cases, built on Apache Lucene.

Recommended Articles

Vector, semantic and hybrid search with OpenSearch

Using OpenSearch as a vector database: knn_vector fields, faiss and lucene engines, HNSW and IVF,...

Cross-cluster search and cross-cluster replication: multi-cluster Elasticsearch architectures

Design multi-cluster Elasticsearch architectures: remote clusters, cross-cluster search, cross-cl...

Understanding the concept of score

The concept of score allows Elasticsearch to rank your documents by relevance during a search.

Elasticsearch mappings and text analysis: field types, analyzers and dynamic mapping

Master Elasticsearch mappings: field types (text, keyword, numeric, date, ip, nested), multi-fiel...

Grafana Loki vs Elasticsearch: the battle of log storage

A comparison between Loki, the Prometheus-inspired log system, and Elasticsearch, the reference f...

Full-text search in OpenSearch: analyzers and relevance

Mastering full-text search: inverted index, analyzers (including French), the _analyze API, match...

Advanced Elasticsearch Query DSL and aggregations, with ES|QL

Write advanced Elasticsearch queries: bool, filter and score, nested, function_score and BM25 rel...

Vector: sinks in detail (destinations, batches, buffers and retries)

Send Vector events: Loki, Elasticsearch, S3, Kafka, OpenTelemetry, Prometheus, Datadog, HTTP and ...

Fluent Bit or Vector? Choosing, combining and migrating

Compare Fluent Bit and Vector (performance, transformations, ecosystem, governance), combine them...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!