# How to Use Custom Embeddings (Ollama) for Hybrid Search in Elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-to-use-custom-embeddings-ollama-for-hybrid-search-in-elasticsearch/378323>\
**Category:** Elasticsearch\
**Created:** [May 20, 2025, 4:58am UTC](https://discuss.elastic.co/t/how-to-use-custom-embeddings-ollama-for-hybrid-search-in-elasticsearch/378323 "2025-05-20T04:58:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Muhammad\_Fhadli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/muhammad_fhadli/32/102950_2.png) [@Muhammad\_Fhadli](https://discuss.elastic.co/u/Muhammad_Fhadli)\
**Post date:** [May 20, 2025, 4:58am UTC](https://discuss.elastic.co/t/how-to-use-custom-embeddings-ollama-for-hybrid-search-in-elasticsearch/378323/1 "2025-05-20T04:58:18Z")

</div>

I'm trying to combine lexical search and semantic search using the RRF (Reciprocal Rank Fusion) algorithm, as described in the Elasticsearch documentation:

> **[Tutorial: hybrid search with semantic\_text | Elasticsearch Guide \[8.18\] |...](https://www.elastic.co/guide/en/elasticsearch/reference/8.18/semantic-text-hybrid-search.html)**

Since my data is in Indonesian, I need to use a custom embedding model. In my case, I'm using Ollama for generating embeddings. However, I haven't been able to find any tutorials on how to integrate a custom embedding model like this into Elasticsearch for hybrid search.

Could anyone point me in the right direction or share an example?

---

<div class="post-metadata">

**Author:** ![JD\_Armada](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jd_armada/32/142652_2.png) [@JD\_Armada](https://discuss.elastic.co/u/JD_Armada)\
**Post date:** [May 20, 2025, 6:15pm UTC](https://discuss.elastic.co/t/how-to-use-custom-embeddings-ollama-for-hybrid-search-in-elasticsearch/378323/2 "2025-05-20T18:15:47Z")

</div>

Hey Muhammad, welcome back!

I think there's a bit of a disconnect with the usage of the `semantic_text` field here for what you want to accomplish. The `semantic_text` field you linked is a specific way to quickly implement semantic search but it is tied to ELSER as an embedding model. As far as I know there is no way to plug in your own model. What you want to do with combining lexical and semantic search is still possible with your own embedding model, it just takes a few extra steps.

1. Generate embeddings using your preferred model.
2. Index those embeddings into Elasticsearch (Use the type: `dense_vector`).
3. When you go to query, generate an embedding for your query using the same model.
4. Run a `knn` search (This is effectively your vector/semantic search).
5. Combine the results under a standard `match` query using RRF.

Here's some resources to help you get started:

- [Reciprocal Rank Fusion](https://www.elastic.co/docs/reference/elasticsearch/rest-apis/reciprocal-rank-fusion)
- [Dense Vector Fields](https://www.elastic.co/docs/reference/elasticsearch/mapping-reference/dense-vector)
- [Grounding RAG Applications](https://github.com/carlyrichmond/grounding-rag-applications-workshop/tree/main): This workshop uses Ollama to generate embeddings and Elasticsearch to perform vector search, follow along the worksheets and diagrams:

Good luck! Let me know if you get stuck.
