# Custom cluster action

**URL:** <https://discuss.elastic.co/t/custom-cluster-action/20714>\
**Category:** Elasticsearch\
**Created:** [November 12, 2014, 8:50pm UTC](https://discuss.elastic.co/t/custom-cluster-action/20714 "2014-11-12T20:50:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pawel\_Rog](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawel_rog/32/141223_2.png) [@Pawel\_Rog](https://discuss.elastic.co/u/Pawel_Rog)\
**Post date:** [November 12, 2014, 8:50pm UTC](https://discuss.elastic.co/t/custom-cluster-action/20714/1 "2014-11-12T20:50:00Z")

</div>

Hi,  
I'm thinking about building custom ClusterAction. I see that I can build  
custom classes for Request, NodeResponse and NodesRespone but it is not  
clear to me how I can register my custom action.

In case of Rest action it was quite easy because in plugin i simply use

```
public void onModule(RestModule module) {
    module.addRestAction(RestCustomAction.class);
}

```

but I cannot find any examples how I can do this in case of custom  
ClusterAction.

Does anybody have any example how I can achieve this? Thanks for your help.

--  
Paweł Róg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPoNd4yZLdow\_sMJmpN8dr0krEipTX9SbMOp%2BugM0L8\_w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPoNd4yZLdow_sMJmpN8dr0krEipTX9SbMOp%2BugM0L8_w%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [November 12, 2014, 9:23pm UTC](https://discuss.elastic.co/t/custom-cluster-action/20714/2 "2014-11-12T21:23:50Z")

</div>

There is also an ActionModule

public void onModule(ActionModule module) {  
module.registerAction(MyAction.INSTANCE, TransportMyAction.class);  
}

It is always easier to follow existing plugins.

Cheers,

Ivan

On Wed, Nov 12, 2014 at 3:50 PM, Pawel [prog88@gmail.com](mailto:prog88@gmail.com) wrote:

> Hi,  
> I'm thinking about building custom ClusterAction. I see that I can build  
> custom classes for Request, NodeResponse and NodesRespone but it is not  
> clear to me how I can register my custom action.
> 
> In case of Rest action it was quite easy because in plugin i simply use
> 
> ```
> public void onModule(RestModule module) {
> module.addRestAction(RestCustomAction.class);
> }
> 
> ```
> 
> but I cannot find any examples how I can do this in case of custom  
> ClusterAction.
> 
> Does anybody have any example how I can achieve this? Thanks for your help.
> 
> --  
> Paweł Róg
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPoNd4yZLdow\_sMJmpN8dr0krEipTX9SbMOp%2BugM0L8\_w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPoNd4yZLdow_sMJmpN8dr0krEipTX9SbMOp%2BugM0L8_w%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPoNd4yZLdow\_sMJmpN8dr0krEipTX9SbMOp%2BugM0L8\_w%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPoNd4yZLdow_sMJmpN8dr0krEipTX9SbMOp%2BugM0L8_w%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCTD3ZTreOTPXzd1ifwTqyFj3rzRd8KOsZxs8y6qg-M3Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCTD3ZTreOTPXzd1ifwTqyFj3rzRd8KOsZxs8y6qg-M3Q%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Pawel\_Rog](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawel_rog/32/141223_2.png) [@Pawel\_Rog](https://discuss.elastic.co/u/Pawel_Rog)\
**Post date:** [November 13, 2014, 6:05am UTC](https://discuss.elastic.co/t/custom-cluster-action/20714/3 "2014-11-13T06:05:51Z")

</div>

Hi,  
Thank you very much 🙂

Paweł

On Wed, Nov 12, 2014 at 10:23 PM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> There is also an ActionModule
> 
> public void onModule(ActionModule module) {  
> module.registerAction(MyAction.INSTANCE, TransportMyAction.class);  
> }
> 
> It is always easier to follow existing plugins.
> 
> Cheers,
> 
> Ivan
> 
> On Wed, Nov 12, 2014 at 3:50 PM, Pawel [prog88@gmail.com](mailto:prog88@gmail.com) wrote:
> 
> > Hi,  
> > I'm thinking about building custom ClusterAction. I see that I can build  
> > custom classes for Request, NodeResponse and NodesRespone but it is not  
> > clear to me how I can register my custom action.
> > 
> > In case of Rest action it was quite easy because in plugin i simply use
> > 
> > ```
> > public void onModule(RestModule module) {
> > module.addRestAction(RestCustomAction.class);
> > }
> > 
> > ```
> > 
> > but I cannot find any examples how I can do this in case of custom  
> > ClusterAction.
> > 
> > Does anybody have any example how I can achieve this? Thanks for your  
> > help.
> > 
> > --  
> > Paweł Róg
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPoNd4yZLdow\_sMJmpN8dr0krEipTX9SbMOp%2BugM0L8\_w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPoNd4yZLdow_sMJmpN8dr0krEipTX9SbMOp%2BugM0L8_w%40mail.gmail.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPoNd4yZLdow\_sMJmpN8dr0krEipTX9SbMOp%2BugM0L8\_w%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPoNd4yZLdow_sMJmpN8dr0krEipTX9SbMOp%2BugM0L8_w%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCTD3ZTreOTPXzd1ifwTqyFj3rzRd8KOsZxs8y6qg-M3Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCTD3ZTreOTPXzd1ifwTqyFj3rzRd8KOsZxs8y6qg-M3Q%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCTD3ZTreOTPXzd1ifwTqyFj3rzRd8KOsZxs8y6qg-M3Q%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCTD3ZTreOTPXzd1ifwTqyFj3rzRd8KOsZxs8y6qg-M3Q%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPQAoyQZ2drbscN%3DwV-rVXG7r%3DppvHWx%2BdkqrtF%2B\_Cwvg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPQAoyQZ2drbscN%3DwV-rVXG7r%3DppvHWx%2BdkqrtF%2B_Cwvg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ali\_Lotfdar](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Ali\_Lotfdar](https://discuss.elastic.co/u/Ali_Lotfdar)\
**Post date:** [March 26, 2015, 8:26pm UTC](https://discuss.elastic.co/t/custom-cluster-action/20714/4 "2015-03-26T20:26:41Z")

</div>

Hi Pawel,

I am new in creating action plugin, and I found you have already work on  
it. Could you please let me know if there is any sample and explanation  
which can help me to start.  
I already reviewed cookbook ES, but I could not understand its explanation!

Thank you.

Regards,  
Ali

On Thursday, November 13, 2014 at 1:06:00 AM UTC-5, Paweł Róg wrote:

> Hi,  
> Thank you very much 🙂
> 
> Paweł
> 
> On Wed, Nov 12, 2014 at 10:23 PM, Ivan Brusic \<[iv...@brusic.com](mailto:iv...@brusic.com)  
> \<javascript:\>\> wrote:
> 
> > There is also an ActionModule
> > 
> > public void onModule(ActionModule module) {  
> > module.registerAction(MyAction.INSTANCE, TransportMyAction.class);  
> > }
> > 
> > It is always easier to follow existing plugins.
> > 
> > Cheers,
> > 
> > Ivan
> > 
> > On Wed, Nov 12, 2014 at 3:50 PM, Pawel \<[pro...@gmail.com](mailto:pro...@gmail.com) \<javascript:\>\>  
> > wrote:
> > 
> > > Hi,  
> > > I'm thinking about building custom ClusterAction. I see that I can build  
> > > custom classes for Request, NodeResponse and NodesRespone but it is not  
> > > clear to me how I can register my custom action.
> > > 
> > > In case of Rest action it was quite easy because in plugin i simply use
> > > 
> > > ```
> > > public void onModule(RestModule module) {
> > > module.addRestAction(RestCustomAction.class);
> > > }
> > > 
> > > ```
> > > 
> > > but I cannot find any examples how I can do this in case of custom  
> > > ClusterAction.
> > > 
> > > Does anybody have any example how I can achieve this? Thanks for your  
> > > help.
> > > 
> > > --  
> > > Paweł Róg
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPoNd4yZLdow\_sMJmpN8dr0krEipTX9SbMOp%2BugM0L8\_w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPoNd4yZLdow_sMJmpN8dr0krEipTX9SbMOp%2BugM0L8_w%40mail.gmail.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPoNd4yZLdow\_sMJmpN8dr0krEipTX9SbMOp%2BugM0L8\_w%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPoNd4yZLdow_sMJmpN8dr0krEipTX9SbMOp%2BugM0L8_w%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCTD3ZTreOTPXzd1ifwTqyFj3rzRd8KOsZxs8y6qg-M3Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCTD3ZTreOTPXzd1ifwTqyFj3rzRd8KOsZxs8y6qg-M3Q%40mail.gmail.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCTD3ZTreOTPXzd1ifwTqyFj3rzRd8KOsZxs8y6qg-M3Q%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCTD3ZTreOTPXzd1ifwTqyFj3rzRd8KOsZxs8y6qg-M3Q%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/787c2ad8-ec02-44c2-a8e3-1fc7d3ad6a05%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/787c2ad8-ec02-44c2-a8e3-1fc7d3ad6a05%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Pawel\_Rog](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawel_rog/32/141223_2.png) [@Pawel\_Rog](https://discuss.elastic.co/u/Pawel_Rog)\
**Post date:** [March 26, 2015, 9:50pm UTC](https://discuss.elastic.co/t/custom-cluster-action/20714/5 "2015-03-26T21:50:48Z")

</div>

Hi Ali,

I used ClusterAction for my case because I had to execute action on all  
nodes. I used something like this

public class CustomAction extends  
ClusterAction\<CustomRequest, CustomResponse, CustomRequestBuilder\>{  
... implement all required methods (override newRequestBuilder and  
newResponse) ...

public class CustomNodeResponse extends NodeOperationResponse {  
}

public class CustomRequest extends NodesOperationRequest {  
... overide writeTo and readFrom methods ...  
... add custom data fields in this class ... (for example I used "id" which  
was given in constructor and read/write in overridden methods ...

public class CustomRequestBuilder extends  
NodesOperationRequestBuilder\<CustomRequest,  
CustomResponse, CustomRequestBuilder\> {  
... override doExecute method. I used something below ...  
@Override  
protected void doExecute(ActionListener listener) {  
client.execute(CustomAction.INSTANCE, request, listener);  
}

public class CustomResponse extends  
NodesOperationResponse {  
... implement writeTo and readFrom methods ...

public class NodeCustomResponse extends NodeOperationResponse {  
... implement writeTo and readFrom methods ...

And finally the most important part

public class TransportCustomAction extends  
TransportNodesOperationAction\<CustomRequest, CustomResponse,  
TransportCustomAction.NodeCustomRequest, NodeCustomResponse\> {  
... the main part is in nodeOperation method. here is implementation of  
your action ...

--  
Paweł Róg

On Thursday, March 26, 2015 at 9:26:41 PM UTC+1, Ali Lotfdar wrote:

> Hi Pawel,
> 
> I am new in creating action plugin, and I found you have already work on  
> it. Could you please let me know if there is any sample and explanation  
> which can help me to start.  
> I already reviewed cookbook ES, but I could not understand its explanation!
> 
> Thank you.
> 
> Regards,  
> Ali
> 
> On Thursday, November 13, 2014 at 1:06:00 AM UTC-5, Paweł Róg wrote:
> 
> > Hi,  
> > Thank you very much 🙂
> > 
> > Paweł
> > 
> > On Wed, Nov 12, 2014 at 10:23 PM, Ivan Brusic [iv...@brusic.com](mailto:iv...@brusic.com) wrote:
> > 
> > > There is also an ActionModule
> > > 
> > > public void onModule(ActionModule module) {  
> > > module.registerAction(MyAction.INSTANCE, TransportMyAction.class);  
> > > }
> > > 
> > > It is always easier to follow existing plugins.
> > > 
> > > Cheers,
> > > 
> > > Ivan
> > > 
> > > On Wed, Nov 12, 2014 at 3:50 PM, Pawel [pro...@gmail.com](mailto:pro...@gmail.com) wrote:
> > > 
> > > > Hi,  
> > > > I'm thinking about building custom ClusterAction. I see that I can  
> > > > build custom classes for Request, NodeResponse and NodesRespone but it is  
> > > > not clear to me how I can register my custom action.
> > > > 
> > > > In case of Rest action it was quite easy because in plugin i simply use
> > > > 
> > > > ```
> > > > public void onModule(RestModule module) {
> > > > module.addRestAction(RestCustomAction.class);
> > > > }
> > > > 
> > > > ```
> > > > 
> > > > but I cannot find any examples how I can do this in case of custom  
> > > > ClusterAction.
> > > > 
> > > > Does anybody have any example how I can achieve this? Thanks for your  
> > > > help.
> > > > 
> > > > --  
> > > > Paweł Róg
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPoNd4yZLdow\_sMJmpN8dr0krEipTX9SbMOp%2BugM0L8\_w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPoNd4yZLdow_sMJmpN8dr0krEipTX9SbMOp%2BugM0L8_w%40mail.gmail.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPoNd4yZLdow\_sMJmpN8dr0krEipTX9SbMOp%2BugM0L8\_w%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAF9ZkbPoNd4yZLdow_sMJmpN8dr0krEipTX9SbMOp%2BugM0L8_w%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> > > > .  
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCTD3ZTreOTPXzd1ifwTqyFj3rzRd8KOsZxs8y6qg-M3Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCTD3ZTreOTPXzd1ifwTqyFj3rzRd8KOsZxs8y6qg-M3Q%40mail.gmail.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCTD3ZTreOTPXzd1ifwTqyFj3rzRd8KOsZxs8y6qg-M3Q%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCTD3ZTreOTPXzd1ifwTqyFj3rzRd8KOsZxs8y6qg-M3Q%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/58822bc2-dfe0-429a-be6c-e372e700396c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/58822bc2-dfe0-429a-be6c-e372e700396c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 12:23am UTC](https://discuss.elastic.co/t/custom-cluster-action/20714/6 "2017-07-06T00:23:34Z")

</div>


