ariel
(ariel)
April 1, 2015, 8:10am
1
I'm attempting to write unit test for my code which searches through a
number of indexes and only returns documents which match a certain term.
The query i use is rather simple:
{
"query":
{
"from" : 0,
"size" : 20,
"query" : {
"term" : {
"resource_affectedID" : 206158433329
}
},
"aggregations" : {
"count" : {
"value_count" : {
"field" : "resource_affectedID"
}
}
}
}
}
This works against a real cluster but when I run this query against a
client from ElasticsearchSingleNodeTest I always get empty results.
My test cluster is being populated from real records. For the records i
have an array of the _source in entries.json they are inserted into the
cluster with the following code:
String index = "audit-2015.01.01";
createIndex(index);
File entriesFile = getResource("entries.json");
JSONParser jsonParser = new JSONParser();
JSONArray entries = (JSONArray) jsonParser.parse(new FileReader(entriesFile
));
for (Object entry : entries) {
IndexRequestBuilder builder = new IndexRequestBuilder(client());
builder.setOpType(IndexRequest.OpType.CREATE);
builder.setSource(entry.toString().getBytes());
builder.setIndex(index);
builder.setType("application_logs");
builder.setId(id.toString());
client().index(builder.request()).actionGet();
id++;
}
client().admin().indices().flush(new FlushRequest(index)).actionGet();
Any ideas why this works in a real cluster and not here?
--
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/c0782988-edd3-4e8d-9bed-ea0b755d5ce4%40googlegroups.com .
For more options, visit https://groups.google.com/d/optout .
dadoonet
(David Pilato)
April 1, 2015, 8:25am
2
You need to run a refresh, not a flush.
My 2 cents
--
David Pilato - Developer | Evangelist
Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.
@dadoonet https://twitter.com/dadoonet | @elasticsearchfr https://twitter.com/elasticsearchfr | @scrutmydocs https://twitter.com/scrutmydocs
Le 1 avr. 2015 à 10:10, ariel@symphony.com a écrit :
I'm attempting to write unit test for my code which searches through a number of indexes and only returns documents which match a certain term.
The query i use is rather simple:
{
"query":
{
"from" : 0,
"size" : 20,
"query" : {
"term" : {
"resource_affectedID" : 206158433329
}
},
"aggregations" : {
"count" : {
"value_count" : {
"field" : "resource_affectedID"
}
}
}
}
}
This works against a real cluster but when I run this query against a client from ElasticsearchSingleNodeTest I always get empty results.
My test cluster is being populated from real records. For the records i have an array of the _source in entries.json they are inserted into the cluster with the following code:
String index = "audit-2015.01.01";
createIndex(index);
File entriesFile = getResource("entries.json");
JSONParser jsonParser = new JSONParser();
JSONArray entries = (JSONArray) jsonParser.parse(new FileReader(entriesFile));
for (Object entry : entries) {
IndexRequestBuilder builder = new IndexRequestBuilder(client());
builder.setOpType(IndexRequest.OpType.CREATE);
builder.setSource(entry.toString().getBytes());
builder.setIndex(index);
builder.setType("application_logs");
builder.setId(id.toString());
client().index(builder.request()).actionGet();
id++;
}
client().admin().indices().flush(new FlushRequest(index)).actionGet();
Any ideas why this works in a real cluster and not here?
--
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/c0782988-edd3-4e8d-9bed-ea0b755d5ce4%40googlegroups.com https://groups.google.com/d/msgid/elasticsearch/c0782988-edd3-4e8d-9bed-ea0b755d5ce4%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/6B3833A7-286B-4FD2-AFAE-B571F9690451%40pilato.fr .
For more options, visit https://groups.google.com/d/optout .
ariel
(ariel)
April 1, 2015, 8:41am
3
I tried added this line:
client().admin().indices().refresh(new RefreshRequest(index)).actionGet();
and that worked.
Thanks!
On Wednesday, April 1, 2015 at 1:25:55 AM UTC-7, David Pilato wrote:
You need to run a refresh, not a flush.
My 2 cents
--
David Pilato - Developer | Evangelist
elastic.co http://elastic.co
@dadoonet https://twitter.com/dadoonet | @elasticsearchfr
https://twitter.com/elasticsearchfr | @scrutmydocs
https://twitter.com/scrutmydocs
Le 1 avr. 2015 à 10:10, ar...@symphony.com <javascript:> a écrit :
I'm attempting to write unit test for my code which searches through a
number of indexes and only returns documents which match a certain term.
The query i use is rather simple:
{
"query":
{
"from" : 0,
"size" : 20,
"query" : {
"term" : {
"resource_affectedID" : 206158433329
}
},
"aggregations" : {
"count" : {
"value_count" : {
"field" : "resource_affectedID"
}
}
}
}
}
This works against a real cluster but when I run this query against a
client from ElasticsearchSingleNodeTest I always get empty results.
My test cluster is being populated from real records. For the records i
have an array of the _source in entries.json they are inserted into the
cluster with the following code:
String index = "audit-2015.01.01";
createIndex(index);
File entriesFile = getResource("entries.json");
JSONParser jsonParser = new JSONParser();
JSONArray entries = (JSONArray) jsonParser.parse(new FileReader(
entriesFile));
for (Object entry : entries) {
IndexRequestBuilder builder = new IndexRequestBuilder(client());
builder.setOpType(IndexRequest.OpType.CREATE);
builder.setSource(entry.toString().getBytes());
builder.setIndex(index);
builder.setType("application_logs");
builder.setId(id.toString());
client().index(builder.request()).actionGet();
id++;
}
client().admin().indices().flush(new FlushRequest(index)).actionGet();
Any ideas why this works in a real cluster and not here?
--
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/c0782988-edd3-4e8d-9bed-ea0b755d5ce4%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/c0782988-edd3-4e8d-9bed-ea0b755d5ce4%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/4cc26945-5211-49e5-911e-02edbd74fb57%40googlegroups.com .
For more options, visit https://groups.google.com/d/optout .