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 #
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.
