Hi,
I am trying to write a simple client in Java using the High Level REST Client, but I am facing a problem. I have an insert method that creates new documents from a JSON and it seems to be working, but I can't query the inserted data.
The result of the insert query is IndexResponse[index=test,type=_doc,id=0,version=1,result=created,seqNo=0,primaryTerm=1,shards={"total":3,"successful":1,"failed":0}]
which is supposed to mean it worked. But the result of the read query I make after that on that same data is {"took":3,"timed_out":false,"_shards":{"total":3,"successful":3,"skipped":0,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}
.
I also tried to visualize my data in Kibana, but even there my index is empty.
My code :
public void insert(String table, long timestamp, String tags, String fields) {
Map<String, Object> jsonMap = new HashMap<>();
String tagsArray = tags.split(",");
String fieldsArray = fields.split(",");
for (String t : tagsArray) jsonMap.put(t.split("=")[0], t.split("=")[1]);
for (String f : fieldsArray) jsonMap.put(f.split("=")[0], f.split("=")[1]);
jsonMap.put("@timestamp", timestamp);
try {
IndexRequest request = new IndexRequest(table)
.id(Integer.toString(this.elts))
.type("_doc")
.source(jsonMap);
System.out.println(request.toString());
this.elts++;
request.opType("create");
IndexResponse response = client.index(request, RequestOptions.DEFAULT);
System.out.println(response.toString());
}catch (Exception e) {
System.out.println("Insertion failed");
e.printStackTrace();
}
}
What did I do wrong ?