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
@dadoonet <https://twitter.com/dadoonet> | @elasticsearchfr 
<https://twitter.com/elasticsearchfr> | @scrutmydocs 
<https://twitter.com/scrutmydocs>



> Le 6 janv. 2015 à 14:57, Klausen Schaefersinho <[email protected]> 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";)
>    .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";)
>    .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 [email protected] 
> <mailto:[email protected]>.
> 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?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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/67FB1382-4059-4B43-8DD3-FCF742179394%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.

Reply via email to