Search and AI: lexical, vector, hybrid, reranking, and RAG
What this domain covers
The Search and AI domain checks that you can build and inspect retrieval in Kibana and Elasticsearch: lexical BM25, dense and sparse vector search, hybrid fusion, reranking, and retrieval-augmented generation (RAG) in Playground. Questions tend to probe which setting changes recall versus latency, and whether you can read a retriever tree and predict what it returns.
Core rules
- BM25 scores
textfields throughmatch; the analyzer chosen at mapping time decides what is searchable.keywordfields match exactly or via prefix/wildcard, not by relevance. dense_vectorrequiresdimsandsimilarity(cosine,dot_product,euclidean,max_inner_product).dot_productexpects unit-length vectors; cosine ignores magnitude.- Approximate kNN runs through the
knnclause of_searchwithfield,query_vector,k, andnum_candidates.num_candidatesis the per-shard candidate pool and must be at leastk; raising it improves recall and costs latency.kis the number of nearest neighbours considered, bounded bysize. - HNSW settings
mandef_constructionare fixed at mapping time; changing them means reindexing. semantic_textdeclares an inference endpoint in the mapping, chunks and embeds at ingest, and is queried with thesemanticquery. It removes manual vector plumbing but pins the field to that model, so switching models requires reindexing.- ELSER is a learned sparse encoder stored in a
sparse_vectorfield: strong on lexical-semantic overlap and easier to explain than dense vectors. - Hybrid search fuses two retrievers. RRF scores each document as 1/(rank_constant + rank) per result list (default
rank_constant60) and ignores raw scores, so no score normalization is needed. Thelinearretriever instead combines normalized scores with weights. - Reranking wraps a first stage:
text_similarity_rerankerreorders the toprank_window_sizedocuments using an inference endpoint such as Elastic Rerank.
Worked example
A support index has body (text) and body_vector. A user searches for reset password INC-4471. Pure kNN returns paraphrases but drops the exact ticket ID; BM25 does the opposite. Build an rrf retriever with a standard child (match on body) and a knn child (k: 50, num_candidates: 200). RRF merges by rank, so the BM25 ticket hit and the kNN paraphrase both survive. Then wrap the result in text_similarity_reranker with rank_window_size 50 to fix ordering inside that window. The reasoning: fusion repairs recall, the reranker repairs precision, and neither can rescue a document the first stage never returned.
Traps
Reading num_candidates as the result count, or setting it below k. Expecting a reranker to promote documents outside its window. Assuming RRF respects a very high BM25 score - it only sees rank. Forgetting that semantic_text ingestion fails when the inference endpoint is missing or unhealthy. Confusing Playground, which is query-time RAG over existing indices, with an ingest pipeline.