# Elastic Action plugin

**URL:** <https://discuss.elastic.co/t/elastic-action-plugin/372225>\
**Category:** Elasticsearch\
**Created:** [December 19, 2024, 1:51pm UTC](https://discuss.elastic.co/t/elastic-action-plugin/372225 "2024-12-19T13:51:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![regepiyu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/regepiyu/32/140190_2.png) [@regepiyu](https://discuss.elastic.co/u/regepiyu)\
**Post date:** [December 19, 2024, 1:51pm UTC](https://discuss.elastic.co/t/elastic-action-plugin/372225/1 "2024-12-19T13:51:03Z")

</div>

I have created Custom Action plugin for elastic in java. This plugin have rest handler for preparing request, action and transport action which has actual business logic for executing request.  
This plugin was designed to find correct index from alias and update/insert the requested document in the same.  
This works fine when I run for single document.

For bulk call, I wanted to add multithreading so that it will call action for each record in parallel.

I have used Executor service and submitted client.execute method in the loop of record list.

I am running this plugin on the cluster with elastic superuser.

It works fine for single document but when I try to call bulk, it gives me security exception as  
org.elasticsearch.ElasticsearchSecurityException: action [cluster:admin/custom\_updateorinsert] is unauthorised for user [\_system] with effective roles [\_system] , this action is granted by the cluster privileges [manage,all]

I am not using \_system user anywhere in the code. Is there any way where we can avoid using internal user \_system and use only elastic or user which I am passing in the request.  
Also I am not sure from where \_system is being used , is it because I used Executor to call client api.

---

<div class="post-metadata">

**Author:** ![TimV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timv/32/13162_2.png) [@TimV](https://discuss.elastic.co/u/TimV)\
**Post date:** [December 30, 2024, 12:27am UTC](https://discuss.elastic.co/t/elastic-action-plugin/372225/2 "2024-12-30T00:27:23Z")

</div>

> [@regepiyu](#):
>
> I have used Executor service and submitted client.execute method in the loop of record list.

It sounds like you created your own executor service - if so, don't do that.

You need to work with Elasticsearch's thread pool model so that the correct contextual information is applied to each thread.

Look at `org.elasticsearch.threadpool.ThreadPool.GENERIC` or `Plugin.getExecutorBuilders`

---

<div class="post-metadata">

**Author:** ![regepiyu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/regepiyu/32/140190_2.png) [@regepiyu](https://discuss.elastic.co/u/regepiyu)\
**Post date:** [January 2, 2025, 2:03pm UTC](https://discuss.elastic.co/t/elastic-action-plugin/372225/3 "2025-01-02T14:03:52Z")

</div>

Thanks for the reply.  
It worked for me after using elasticsearch thread service

---

<div class="post-metadata">

**Author:** ![regepiyu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/regepiyu/32/140190_2.png) [@regepiyu](https://discuss.elastic.co/u/regepiyu)\
**Post date:** [February 13, 2025, 12:57pm UTC](https://discuss.elastic.co/t/elastic-action-plugin/372225/4 "2025-02-13T12:57:41Z")

</div>

Hi,

As per last thread, I have used Elasticsearch threadmodel. Since I need to ingest/update document, I have used write threadpool while creating executor.  
But after that it appears to me that some times, other working threads on same node blocks my java code thread and it causes to stuck the thread.  
Can you please suggest how to handle this scenario.
