# Data inserted via Java API is not visible

**URL:** <https://discuss.elastic.co/t/data-inserted-via-java-api-is-not-visible/173984>\
**Category:** Elasticsearch\
**Created:** [March 26, 2019, 5:37pm UTC](https://discuss.elastic.co/t/data-inserted-via-java-api-is-not-visible/173984 "2019-03-26T17:37:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thebuleon29](https://avatars.discourse-cdn.com/v4/letter/t/bbce88/32.png) [@thebuleon29](https://discuss.elastic.co/u/thebuleon29)\
**Post date:** [March 26, 2019, 5:37pm UTC](https://discuss.elastic.co/t/data-inserted-via-java-api-is-not-visible/173984/1 "2019-03-26T17:37:37Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [March 26, 2019, 6:37pm UTC](https://discuss.elastic.co/t/data-inserted-via-java-api-is-not-visible/173984/2 "2019-03-26T18:37:24Z")

</div>

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

You must [refresh](https://www.elastic.co/guide/en/elasticsearch/reference/6.6/indices-refresh.html) an index to make newly-inserted data visible to searches. You can also [do this while indexing documents](https://www.elastic.co/guide/en/elasticsearch/reference/6.6/docs-refresh.html). It doesn't look like you're doing either of these things.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 23, 2019, 6:37pm UTC](https://discuss.elastic.co/t/data-inserted-via-java-api-is-not-visible/173984/3 "2019-04-23T18:37:29Z")

</div>

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