adding document not working by using Bulk API JAVA

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

adding document not working by using Bulk API JAVA

This post has NOT been accepted by the mailing list yet.
Hi! I'm trying to test Bulk API JAVA to reindex Crawler2 to Crawler3. Here is my code

public static void main(String[] args) throws Exception {
                String str_id = "";
                String old_index = "crawler2";
                String new_index = "crawler3";
                String table = "page";
                Settings settings = ImmutableSettings.settingsBuilder().put("", "test-cluster").build();        
                TransportClient client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress("",9300));
                QueryBuilder qb = QueryBuilders.matchAllQuery();
                SearchResponse scrollResp = client.prepareSearch(old_index)
                        .setScroll(new TimeValue(600000))
                        .setSize(100).execute().actionGet(); //100 hits per shard will be returned for each scroll
                //Scroll until no hits are returned
                while (true) {
                                BulkRequestBuilder bulkRequest = client.prepareBulk();
                            for (SearchHit hit : scrollResp.getHits().getHits()) {
                            //System.out.println("str_id : ");
                            str_id = String.valueOf(hit.getId());    
                            bulkRequest.add(client.prepareIndex(new_index, table, str_id)
                            BulkResponse bulkResponse = bulkRequest.execute().actionGet();    
                            scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(600000)).execute().actionGet();    
                            //Break condition: No hits are returned
                            if (scrollResp.getHits().getHits().length == 0) {    
                            System.out.println("len = 0");
                        catch(Exception e){
                                System.out.println("e : "+e);

This code can add 700-900 documents to index and then it will appear error

 org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes were available: [[Chameleon][Yts0j3wlSQaYQA9JUYT4vQ][HawaiSearchEngineTest][inet[/]]{master=true}]

As picture below, at the third line "docs: 781 (1,910)" , the number in bracket (1,910) still increase but document number (781) nothing change.

could you please help me for resolving this issue. Thank you for your help.