15 Mayıs 2023 Pazartesi

ElasticSearch Java API Client ElasticsearchIndicesClient Sınıfı

Giriş
Açıklaması şöyle
All indices related operations form a namespace called “indices”, hence classes and a client related to operations on indices are present in co.elastic.clients.elasticsearch.indices package. As expected, the client supporting the “indices” operations is the ElasticearchIndicesClient. To obtain this client, one must ask the main Java API client (the ElasticsearchClient) to provide the instance of the indices client. 
constructor
Şöyle yaparız
ElasticsearchIndicesClient elasticsearchIndicesClient = elasticsearchClient.indices();
create metodu
Açıklaması şöyle
Once we have the respective client, like ElasticsearchIndicesClient, we can invoke create() method to create an index. The create() method expects a Request object — a CreateIndexRequest object to be precise. This pattern leads to our next request/response pattern.

All methods on the client are expected to be passed in with a request object. As you can expect there are a lot of request classes. Each of these request objects are instantiated using the builder pattern.

Take an example of “creating an index” use case. This requires a CreateIndexRequest to be instantiated with arguments that are required to create an index. 
...

The index() method accepts a string as the name of the index. Once we have the index created, we can then invoke the create method on the indices client by passing this request. 
...

The result of this invocation is captured in the response object: CreateIndexResponse in this case. Again, any invocation will return a response — it follows the same pattern — for example: the CreateIndexRequest’s response would be CreateIndexResponse object. The response object would have all the required information about the newly created index.
Örnek
Şöyle yaparız
CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder()
  .index("flights")
  .build();

CreateIndexResponse createIndexResponse = elasticsearchIndicesClient
  .create(createIndexRequest);


Hiç yorum yok:

Yorum Gönder