# How to find Class implementing Function\< CreateIndexRequest.Builder, ObjectBuilder\< CreateIndexRequest\>\>?

**URL:** <https://discuss.elastic.co/t/how-to-find-class-implementing-function-createindexrequest-builder-objectbuilder-createindexrequest/306114>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [June 1, 2022, 11:09am UTC](https://discuss.elastic.co/t/how-to-find-class-implementing-function-createindexrequest-builder-objectbuilder-createindexrequest/306114 "2022-06-01T11:09:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enomine](https://avatars.discourse-cdn.com/v4/letter/e/f19dbf/32.png) [@Enomine](https://discuss.elastic.co/u/Enomine)\
**Post date:** [June 1, 2022, 11:09am UTC](https://discuss.elastic.co/t/how-to-find-class-implementing-function-createindexrequest-builder-objectbuilder-createindexrequest/306114/1 "2022-06-01T11:09:45Z")

</div>

Hi,

may one create a new index to the client by

```auto
client.indices().create(c -> c.index("products2"));

```

May one other be interested in doing so without using lambda-expression. He will need to give a CreateIndexRequest Object, which can be created by delivering a Function\<CreateIndexRequest.Builder,ObjectBuilder\>.

But how to find a class, that implements this interface?

```auto
public void createClient() throws Exception {
		zset_username_password_host_port(1);
		// https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/connecting.html
		// https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/_basic_authentication.html

		final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
		credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
		HttpClientConfigCallback httpClientConfigCallback = new HttpClientConfigCallback() {
			@Override
			public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
				httpClientBuilder.disableAuthCaching();
				return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
			}
		};

		// Create the low-level client
		RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(host, port, "https"));
		restClientBuilder.setHttpClientConfigCallback(httpClientConfigCallback);
		RestClient restClient = restClientBuilder.build();

		// Create the transport with a Jackson mapper
		ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());

		// And create the API client
		ElasticsearchClient client = new ElasticsearchClient(transport);

		create_index_no_lambda_example(client);
		create_index_lambda_example(client);
		search_example(client);

		restClient.close();
	}

	private void create_index_no_lambda_example(ElasticsearchClient client) throws ElasticsearchException, IOException {
		CreateIndexRequest cir = CreateIndexRequest.of(null); // needs an object implementing Function<CreateIndexRequest.Builder,ObjectBuilder<CreateIndexRequest>>
		client.indices().create(cir);
	}

	private void create_index_lambda_example(ElasticsearchClient client) throws ElasticsearchException, IOException {
		client.indices().create(c -> c.index("products2"));
	}

```

Thanks - Enomine

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [June 1, 2022, 12:16pm UTC](https://discuss.elastic.co/t/how-to-find-class-implementing-function-createindexrequest-builder-objectbuilder-createindexrequest/306114/2 "2022-06-01T12:16:26Z")

</div>

Hi!

I know about this two styles:

```auto
   //Builder Style
    CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder()
        .index("value")
        .build();
    client.indices().create(createIndexRequest);

    //Functional Style
    client.indices().create(CreateIndexRequest.of(
        ir -> ir.index("value")
    ));

```

---

<div class="post-metadata">

**Author:** ![Enomine](https://avatars.discourse-cdn.com/v4/letter/e/f19dbf/32.png) [@Enomine](https://discuss.elastic.co/u/Enomine)\
**Post date:** [June 2, 2022, 8:53am UTC](https://discuss.elastic.co/t/how-to-find-class-implementing-function-createindexrequest-builder-objectbuilder-createindexrequest/306114/3 "2022-06-02T08:53:05Z")

</div>

Okay thanks. This works. Here are 2 more working examples to create an index:

```auto
private void create_index_functional_style(ElasticsearchClient client) throws ElasticsearchException, IOException {
		client.indices().create(CreateIndexRequest.of(ir -> ir.index("products4")));
	}

	private void create_index_builder_style(ElasticsearchClient client) throws ElasticsearchException, IOException {
		CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index("products5").build();
		client.indices().create(createIndexRequest);
	}
	

	private void create_index_lambda_example(ElasticsearchClient client) throws ElasticsearchException, IOException {
		client.indices().create(c -> c.index("products2"));
	}

	private void create_index_no_lambda_example(ElasticsearchClient client) throws ElasticsearchException, IOException {
		CreateIndexRequest cir = CreateIndexRequest.of(new Function<CreateIndexRequest.Builder, ObjectBuilder<CreateIndexRequest>>() {

			@Override
			public ObjectBuilder<CreateIndexRequest> apply(Builder t) {
				return t.index("products3");
			}

		});
		client.indices().create(cir);
	}

```

Thanks - Enomine

---

<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:** [June 30, 2022, 8:54am UTC](https://discuss.elastic.co/t/how-to-find-class-implementing-function-createindexrequest-builder-objectbuilder-createindexrequest/306114/4 "2022-06-30T08:54:04Z")

</div>

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