Reputation: 3261
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
Upvotes: 0
Views: 289
Reputation: 22555
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.
Upvotes: 1