Accesiblty of index through java code


after successully setting the Elasticsearch and kibana over ReadOnlyRest,
I want to access my index using my java code.

I have a little bit knowledge of Transport Client.
Can you help me how can i do this.


Akhilesh Tiwari

Hi @Akhilesh,

The use of the transport client is discouraged in favour of the high level rest client.

Actually i have no more idea about High level Rest Client and low level Rest Client.
does ReadOnlyRest supports Transport Client??
can you give me any link for Demo Code,how to access index of elasticsearch using my java code?


Akhileshh Tiwari

Basically the difference is that a Java client using the transport API is difficult to distinguish from a new node joining the cluster and implementing security becomes a messy business.

So Elastic decided to deprecate the transport library for Java apps, in favour of another one that has a very similar Java API, but ultimately sends HTTP requests, rather than Elasticsearch transport frames.

This is a getting started guide from DZone:

Actually my requirement is,I want to Connect elasticsearch to my java code with UserName and Password for access the index .

can you help me out with a small code of java?

A google search said you can initialise the rest client like this:

final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        new UsernamePasswordCredentials("user", "password"));

RestClientBuilder builder = RestClient.builder(new HttpHost("localhost", 9200))
        .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
            public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
                return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);

Then have a look at the docs

Hi Simone Scarduzio,

I have a Serious issue,i am giving only two permissions (Write and Delete) to user1 on index1 by using Admin login ID,when I am going login by user1 without any permission index1 is readable to user1.

so I need your help on priority basis because my licence for ReadOnlyRest Pro is going to expire.
please help me as soon a possible.

Below is my code:

- name: "user1"
  auth_key: user1:user1
  kibana_access: rw 
  indices: [".kibana","index1"]
  kibana_hide_apps: ["readonlyrest_kbn"]
- name: "user1 extra actions to operate index1 from devtools"
  auth_key: user1:user1
  actions: ["indices:admin/delete","indices:data/write/*"]
  indices: ["index1"]
  kibana_hide_apps: ["readonlyrest_kbn"]


Akhilesh Tiwari

@Akhilesh, I think you should talk to @ajit, because you guys are asking the same question in parallel all the time. I already answered him 1 minute ago on another thread.