elasticsearch/elasticsearch — Issue #1612: Add generic execution of APIs to Client (and indices/cluster) and allow for plugins to register custom APIs
Author: kimchy
Created: 2012-01-15 14:14:14+00:00
State: open
Labels: feature, v0.19.0

This change is driven by allowing for plugins to register custom (strongly typed) Java APIs as well as REST APIs. The `Client`, `IndicesAdminClient` and `ClusterAdminClient` interfaces now allow to `execute` and `prepareExecute` custom actions (as well as the built in ones) in a strongly typed manner.

A new class called `GenericAction` was added, where each specific action needs to extend and implement. Main actions need to extend `Action`, indices actions need to extend `IndicesAction` and cluster actions need to extend `ClusterAction`. Those actions need to be strongly types.

Plugins should then use the `ActionModule` module to register custom actions based on the instance of the action, the transport action class, and any supporting classes.

The generic execute usage then requires providing the action when executing, which automatically derives the request and response types based on generic.

For example, here is how an index operation will be executed using the generic execute method:

// direct execution
IndexResponse response = client1.execute(IndexAction.INSTANCE, new IndexRequest(...)...).actionGet();
// prepare sample
client1.prepareExecute(IndexAction.INSTANCE).setIndex("test").setType("type").setSource("").execute().actionGet();

As a side note, implementing custom actions has become much simpler, where transport client level proxies are automatically generated and there is no need to create custom ones per actions.