0

I am trying to index a file by using below code: But I am wondering why it is not happening: Could any body explain the reason for not indexing.

public static void main(String[] args) throws IOException {
    String line;
    List l=new ArrayList();
    FileReader file=new FileReader("test.txt");     
    BufferedReader br=new BufferedReader(file);
    while((line=br.readLine())!=null){
        l.add(line);
    }
    br.close();
    System.out.println(l);
    Client client = new TransportClient().addTransportAddress(new InetSocketTransportAddress("10.210.51.207",9300));    
    BulkRequestBuilder bulkRequest = client.prepareBulk(); 


    // either use client#prepare, or use Requests# to directly build index/delete requests      
    Iterator it=l.iterator();
    while (it.hasNext()){
        String name=(String) it.next();
        bulkRequest.add(client.prepareIndex("cricket", "cric", "1")
                   .setSource(jsonBuilder()                     
                   .startObject() 
                   .field("user", name)
                   .field("postDate", new Date()) 
                   .field("message", "BULK INSERT TEST")
                   .endObject()  
                   )  ); 

    }




    GetResponse getResponse = client.prepareGet("cricket", "cric", "1").execute().actionGet();      
    System.out.println(getResponse.getSourceAsString());
    System.out.println("Bulk request finished");

}

Thans in advance

1 Answer 1

1

You need to execute your bulkRequest to add the document(s) to the index.

Please add the following before your GetResponse.

 BulkResponse bulkResponse = bulkRequest.execute().actionGet();

You can then check the properties on the bulkResponse object to ensure it completed successfully.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.