Issues with java API

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 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.
For more options, visit https://groups.google.com/d/optout.

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 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")
.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 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?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.
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.

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

@dadoonet https://twitter.com/dadoonet | @elasticsearchfr
https://twitter.com/elasticsearchfr | @scrutmydocs
https://twitter.com/scrutmydocs

Le 6 janv. 2015 à 14:57, Klausen Schaefersinho <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")

.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 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?utm_medium=email&utm_source=footer
.
For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/79de28df-abfb-48d7-953e-5560b73975f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.