# Issues with java API

**URL:** https://discuss.elastic.co/t/issues-with-java-api/21504
**Category:** Elasticsearch
**Created:** [January 6, 2015, 1:57pm UTC](https://discuss.elastic.co/t/issues-with-java-api/21504 "2015-01-06T13:57:37Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Klausen\_Schaefersinh](https://avatars.discourse-cdn.com/v4/letter/k/d2c977/32.png) [@Klausen\_Schaefersinh](https://discuss.elastic.co/u/Klausen_Schaefersinh)
#### Post date: [January 6, 2015, 1:57pm UTC](https://discuss.elastic.co/t/issues-with-java-api/21504/1 "2015-01-06T13:57:37Z")

</div>

Hello,

I am new to ElasticSearch and I was building a simple service that would  
store some documents. I used a local node like :

ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();

settings.put("node.name", "ligatus-dsp-aggregation-embedded");

settings.put("path.data", this.url);

settings.put("http.enabled", false);

Node node = NodeBuilder

.nodeBuilder()

.settings(settings)

.local(true)

.node();

Client client = node.client();

I write then plain json docs into one index and assign already an id:

IndexResponse response = client

.prepareIndex(this.index, this.type, "[http://www.myID.com](http://www.myID.com)")

.setSource(json)

.execute()

.actionGet();

If I try to retrieve the document by its id everything works fine.

GetResponse response = getClient()

.prepareGet(this.index, this.type, "[http://www.myID.com](http://www.myID.com)")

.execute()

.actionGet();

// works fine.

However if I want to search (by field), count and retrieve all entries, I always get 0 resutls. My code looks like:

SearchResponse response = getClient()

.prepareSearch(this.index)

.setTypes(this.type)

.setSearchType(SearchType.QUERY\_AND\_FETCH)

.setQuery(QueryBuilders.matchQuery(aField, aValue))

.execute()

.actionGet();

// 0 hits

I am not sure why this happens? Maybe because the new documents are not indexed and thus not searchable? Or what could be the issue?

Best Regards,

Klaus

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0256f12f-bb8b-49c2-91fc-4159973900aa%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0256f12f-bb8b-49c2-91fc-4159973900aa%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 6, 2015, 2:34pm UTC](https://discuss.elastic.co/t/issues-with-java-api/21504/2 "2015-01-06T14:34:39Z")

</div>

Hard to say but if you are running this in a unit test for example, it’s most likely a refresh issue.  
You need to refresh your index before running the first search.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)

> Le 6 janv. 2015 à 14:57, Klausen Schaefersinho [klaus.schaefers@gmail.com](mailto:klaus.schaefers@gmail.com) a écrit :
> 
> Hello,
> 
> I am new to Elasticsearch and I was building a simple service that would store some documents. I used a local node like :
> 
> ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();  
> settings.put("node.name", "ligatus-dsp-aggregation-embedded");  
> settings.put("path.data", this.url);  
> settings.put("http.enabled", false);  
> Node node = NodeBuilder  
> .nodeBuilder()  
> .settings(settings)  
> .local(true)  
> .node();
> 
> Client client = node.client();
> 
> I write then plain json docs into one index and assign already an id:
> 
> IndexResponse response = client  
> .prepareIndex(this.index, this.type, "[http://www.myID.com](http://www.myID.com)")  
> .setSource(json)  
> .execute()  
> .actionGet();
> 
> If I try to retrieve the document by its id everything works fine.
> 
> GetResponse response = getClient()  
> .prepareGet(this.index, this.type, "[http://www.myID.com](http://www.myID.com)")  
> .execute()  
> .actionGet();
> 
> // works fine.
> 
> However if I want to search (by field), count and retrieve all entries, I always get 0 resutls. My code looks like:
> 
> SearchResponse response = getClient()  
> .prepareSearch(this.index)  
> .setTypes(this.type)  
> .setSearchType(SearchType.QUERY\_AND\_FETCH)  
> .setQuery(QueryBuilders.matchQuery(aField, aValue))  
> .execute()  
> .actionGet();
> 
> // 0 hits
> 
> I am not sure why this happens? Maybe because the new documents are not indexed and thus not searchable? Or what could be the issue?
> 
> Best Regards,
> 
> Klaus
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com) [mailto:elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0256f12f-bb8b-49c2-91fc-4159973900aa%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0256f12f-bb8b-49c2-91fc-4159973900aa%40googlegroups.com) [https://groups.google.com/d/msgid/elasticsearch/0256f12f-bb8b-49c2-91fc-4159973900aa%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/0256f12f-bb8b-49c2-91fc-4159973900aa%40googlegroups.com?utm_medium=email&utm_source=footer).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout) [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/67FB1382-4059-4B43-8DD3-FCF742179394%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/67FB1382-4059-4B43-8DD3-FCF742179394%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Klausen\_Schaefersinh](https://avatars.discourse-cdn.com/v4/letter/k/d2c977/32.png) [@Klausen\_Schaefersinh](https://discuss.elastic.co/u/Klausen_Schaefersinh)
#### Post date: [January 7, 2015, 8:05am UTC](https://discuss.elastic.co/t/issues-with-java-api/21504/3 "2015-01-07T08:05:09Z")

</div>

Yes that was the issue!

On Tuesday, January 6, 2015 3:34:49 PM UTC+1, David Pilato wrote:

> Hard to say but if you are running this in a unit test for example, it’s  
> most likely a refresh issue.  
> You need to refresh your index before running the first search.
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)  
> [http://Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs  
> [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 6 janv. 2015 à 14:57, Klausen Schaefersinho \<[klaus.s...@gmail.com](mailto:klaus.s...@gmail.com)  
> \<javascript:\>\> a écrit :
> 
> Hello,
> 
> I am new to Elasticsearch and I was building a simple service that would  
> store some documents. I used a local node like :
> 
> ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
> 
> settings.put("node.name", "ligatus-dsp-aggregation-embedded");
> 
> settings.put("path.data", this.url);
> 
> settings.put("http.enabled", false);
> 
> Node node = NodeBuilder
> 
> .nodeBuilder()
> 
> .settings(settings)
> 
> .local(true)
> 
> .node();
> 
> Client client = node.client();
> 
> I write then plain json docs into one index and assign already an id:
> 
> IndexResponse response = client
> 
> .prepareIndex(this.index, this.type, "[http://www.myID.com](http://www.myID.com)")
> 
> .setSource(json)
> 
> .execute()
> 
> .actionGet();
> 
> If I try to retrieve the document by its id everything works fine.
> 
> GetResponse response = getClient()
> 
> .prepareGet(this.index, this.type, "[http://www.myID.com](http://www.myID.com)")
> 
> .execute()
> 
> .actionGet();
> 
> // works fine.
> 
> However if I want to search (by field), count and retrieve all entries, I always get 0 resutls. My code looks like:
> 
> SearchResponse response = getClient()
> 
> .prepareSearch(this.index)
> 
> .setTypes(this.type)
> 
> .setSearchType(SearchType.QUERY\_AND\_FETCH)
> 
> .setQuery(QueryBuilders.matchQuery(aField, aValue))
> 
> .execute()
> 
> .actionGet();
> 
> // 0 hits
> 
> I am not sure why this happens? Maybe because the new documents are not indexed and thus not searchable? Or what could be the issue?
> 
> Best Regards,
> 
> Klaus
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/0256f12f-bb8b-49c2-91fc-4159973900aa%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0256f12f-bb8b-49c2-91fc-4159973900aa%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/0256f12f-bb8b-49c2-91fc-4159973900aa%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/0256f12f-bb8b-49c2-91fc-4159973900aa%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/79de28df-abfb-48d7-953e-5560b73975f7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/79de28df-abfb-48d7-953e-5560b73975f7%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [July 6, 2017, 12:40am UTC](https://discuss.elastic.co/t/issues-with-java-api/21504/4 "2017-07-06T00:40:21Z")

</div>


