What is kNN vector search in Elasticsearch 8.x?

Answer

Elasticsearch 8.x introduced native kNN (k-Nearest Neighbor) vector search using the dense_vector field type and the knn query parameter. This enables semantic search and AI-powered retrieval: documents are represented as high-dimensional vectors (embeddings generated by ML models like BERT or OpenAI's text-embedding models), and search finds the k documents whose vectors are closest to the query vector by cosine similarity or dot product. Use cases include semantic document search (finding conceptually similar documents even without keyword overlap), image similarity search, recommendation systems, and anomaly detection. Elasticsearch implements approximate kNN using the HNSW (Hierarchical Navigable Small World) algorithm for efficient similarity search at scale. Combine kNN with bool filters for hybrid search (semantic + keyword).