There's more than one way

I believe the following are all equivalent? Any reason to prefer one
over the other?

A.
CreateIndexRequest request =
Requests.createIndexRequest(index).settings(settings);
client.admin().indices().create(request).actionGet();

B.
CreateIndexRequest request = new
CreateIndexRequest(index).settings(settings);
client.admin().indices().create(request).actionGet();

C.

client.admin().indices().prepareCreate(index).setSettings(settings).execute().actionGet();

Yes, all are the same. A and B are "really" the same (Requests is just a simple static factory), and C was added later on in the life of elasticsearch and the on I recommend (more readable).

On Thursday, February 9, 2012 at 7:53 AM, Eric Jain wrote:

I believe the following are all equivalent? Any reason to prefer one
over the other?

A.
CreateIndexRequest request =
Requests.createIndexRequest(index).settings(settings);
client.admin().indices().create(request).actionGet();

B.
CreateIndexRequest request = new
CreateIndexRequest(index).settings(settings);
client.admin().indices().create(request).actionGet();

C.

client.admin().indices().prepareCreate(index).setSettings(settings).execute().actionGet();

On Feb 9, 12:27 am, Shay Banon kim...@gmail.com wrote:

Yes, all are the same. A and B are "really" the same (Requests is just a simple static factory), and C was added later on in the life of elasticsearch and the on I recommend (more readable).

For the record, there's also an option D: new
SearchRequestBuilder(client)... C and D can be more useful because
some of the builders have more fine-grained methods. For example,
client.prepareSearch(index) returns a SearchRequestBuilder, which has
methods like setQuery, addFacet, setSize etc.
Requests.searchRequest(index) on the other hand returns a
SearchRequest, which requires the same values to be set via a single
call to source(json).

They are nicer to be used, but the builders are just wrappers. For the search aspect, there is also a SearchSourceBuilder that builds the source (and is used internally in the SearchRequestBuilder API).

The RequestBuilders were added later in the lifespan of elasticsearch, and people should use those for simplicity. (the prepareXXX APIs).

On Friday, February 10, 2012 at 9:21 PM, Eric Jain wrote:

On Feb 9, 12:27 am, Shay Banon <kim...@gmail.com (http://gmail.com)> wrote:

Yes, all are the same. A and B are "really" the same (Requests is just a simple static factory), and C was added later on in the life of elasticsearch and the on I recommend (more readable).

For the record, there's also an option D: new
SearchRequestBuilder(client)... C and D can be more useful because
some of the builders have more fine-grained methods. For example,
client.prepareSearch(index) returns a SearchRequestBuilder, which has
methods like setQuery, addFacet, setSize etc.
Requests.searchRequest(index) on the other hand returns a
SearchRequest, which requires the same values to be set via a single
call to source(json).