Data inserted via Java API is not visible

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)
IndexResponse response = client.index(request, RequestOptions.DEFAULT);
}catch (Exception e) {
System.out.println("Insertion failed");

What did I do wrong ?

Please format code using the </> button. It's almost impossible to read otherwise.

You must refresh an index to make newly-inserted data visible to searches. You can also do this while indexing documents. It doesn't look like you're doing either of these things.

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