Accesiblty of index through java code


(Akhilesh Tiwari) #1

Hi,

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.

Thanks 

Akhilesh Tiwari


(Simone Scarduzio) #2

Hi @Akhilesh,

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


(Akhilesh Tiwari) #3

Hi,
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?

  Thanks

Akhileshh Tiwari


How to fetch data using java client
(Simone Scarduzio) #4

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:


(Akhilesh Tiwari) #5

Hi,
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?


(Simone Scarduzio) #6

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

final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
        new UsernamePasswordCredentials("user", "password"));

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

Then have a look at the docs
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/java-rest-low-usage-requests.html


(Akhilesh Tiwari) #7

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"]



Thanks

Akhilesh Tiwari


(Simone Scarduzio) #8

@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.


(Simone Scarduzio) #9