# Using ElasticSearch as a Microservice

**URL:** <https://discuss.elastic.co/t/using-elasticsearch-as-a-microservice/290354>\
**Category:** Elasticsearch\
**Created:** [November 28, 2021, 8:21am UTC](https://discuss.elastic.co/t/using-elasticsearch-as-a-microservice/290354 "2021-11-28T08:21:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohan\_Radhakrishnan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mohan_radhakrishnan/32/79214_2.png) [@Mohan\_Radhakrishnan](https://discuss.elastic.co/u/Mohan_Radhakrishnan)\
**Post date:** [November 28, 2021, 8:21am UTC](https://discuss.elastic.co/t/using-elasticsearch-as-a-microservice/290354/1 "2021-11-28T08:21:59Z")

</div>

Hello,  
This is a design question. We have messages pushed to Kafka and Kafka can pipe it to Elastic using Kafka connect. This is what I am considering for message search. Kafka can send these messages but it also forwards it to the Elasticsearch service. Messages are multi-lingual.

We also need API access to these messages. This is not search. A screen for a particular user will have messages for that user. Traditionally a message micro service is used for this purpose. But I though I could unify the search service and this API.

Can this be done using Elasticsearch ? I can avoid a separate Micro service for this as all the messages are in Elastic now. I plan to explore how Elasticsearch can be hosted in Kubernetes as all our services are there.

The only reason for have a Spring Data Elastic Micro Service is to check some business rules. Has the message been viewed already ? How to expire the messages ? Has the user been blacklisted ?

Thanks.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 28, 2021, 9:29pm UTC](https://discuss.elastic.co/t/using-elasticsearch-as-a-microservice/290354/2 "2021-11-28T21:29:13Z")

</div>

The retrieval of messages for a user would be akin to a search, just with a filter for that user right? So Elasticsearch can do this.

---

<div class="post-metadata">

**Author:** ![Mohan\_Radhakrishnan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mohan_radhakrishnan/32/79214_2.png) [@Mohan\_Radhakrishnan](https://discuss.elastic.co/u/Mohan_Radhakrishnan)\
**Post date:** [November 29, 2021, 2:51pm UTC](https://discuss.elastic.co/t/using-elasticsearch-as-a-microservice/290354/3 "2021-11-29T14:51:07Z")

</div>

Yes. But the layer before Elasticsearch has to take care of checking blacklisted customers and other security restrictions. I assume the Elasticsearch cluster in Kubernetes is better if accessed directly instead of a Spring Data Elastic Micro Service. Any architectural pattern guidance is documented in books etc. ?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 29, 2021, 8:18pm UTC](https://discuss.elastic.co/t/using-elasticsearch-as-a-microservice/290354/4 "2021-11-29T20:18:23Z")

</div>

Elasticsearch has inbuilt, free security features. It doesn't do access blacklisting as such, but you could implement a list of those in an index that you query first with your code, then anything that passes can run another query to get the info it needs.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 27, 2021, 8:18pm UTC](https://discuss.elastic.co/t/using-elasticsearch-as-a-microservice/290354/5 "2021-12-27T20:18:28Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
