JAVA Rest Client Bulk Data insert not working

(Ankur Singla) #1

I am trying to upload bulk data(2Lacs) on my elastic cloud using JAVA REST API. In response am getting 200 status and index is created but data not shown.

final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
                    new UsernamePasswordCredentials("elastic", "xxxxxxxx"));

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

            System.out.println("Inside Main" + client);

            //String actionMetaData = String.format("{ \"index\" : { \"_index\" : \"%s\", \"_type\" : \"%s\" } }%n", "searchable", "data");
            StringBuilder bulkRequestBody = new StringBuilder();

            for(int i=0; i<dataList.length(); ++i) {

                String actionMetaData = String.format("{ \"index\" : { \"_index\" : \"%s\", \"_type\" : \"%s\", \"_id\" : \"%s\"  } }%n", "searchable", "doc", i+"");
                JSONObject dataObj = dataList.getJSONObject(i);

                String jsonData = "{" +
                     "\"search\":"+"\""+dataObj.optString("search", "search")+"\""+","+  
                     "\"searchType\":"+"\""+dataObj.optString("searchType", "searchType")+"\""+","+ 
                     "\"code    \":"+"\""+i+"\""+","+                       



            HttpEntity entity = new NStringEntity(bulkRequestBody.toString(), ContentType.APPLICATION_JSON);
            Response bulkResponse = client.performRequest("POST", "/searchable/doc/_bulk?pretty", Collections.emptyMap(), entity);

In bulkResponse I am getting 200 status searchable index is created but still there is no data in the index.

(David Pilato) #2

Try to remove ?pretty.
That's not how parameters should be passed.

(system) #3

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