Refreshing after green so also recovering replicas will be refreshed.

This commit is contained in:
Boaz Leskes 2013-08-28 08:44:10 +02:00
parent e6dcd137a6
commit 45d4864021
1 changed files with 29 additions and 30 deletions

View File

@ -30,26 +30,25 @@ import org.junit.Test;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
import static org.elasticsearch.index.query.QueryBuilders.rangeQuery; import static org.elasticsearch.index.query.QueryBuilders.rangeQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
public class SimpleSearchTests extends AbstractSharedClusterTest { public class SimpleSearchTests extends AbstractSharedClusterTest {
@Test @Test
public void testSearchNullIndex() { public void testSearchNullIndex() {
try { try {
client().prepareSearch((String)null).setQuery(QueryBuilders.termQuery("_id", "XXX1")).execute().actionGet(); client().prepareSearch((String) null).setQuery(QueryBuilders.termQuery("_id", "XXX1")).execute().actionGet();
assert false; assert false;
} catch (ElasticSearchIllegalArgumentException e) { } catch (ElasticSearchIllegalArgumentException e) {
} }
try { try {
client().prepareSearch((String[])null).setQuery(QueryBuilders.termQuery("_id", "XXX1")).execute().actionGet(); client().prepareSearch((String[]) null).setQuery(QueryBuilders.termQuery("_id", "XXX1")).execute().actionGet();
assert false; assert false;
} catch (ElasticSearchIllegalArgumentException e) { } catch (ElasticSearchIllegalArgumentException e) {
} }
} }
@ -115,8 +114,8 @@ public class SimpleSearchTests extends AbstractSharedClusterTest {
prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.mapping.date.parse_upper_inclusive", false)).execute().actionGet(); prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.mapping.date.parse_upper_inclusive", false)).execute().actionGet();
client().prepareIndex("test", "type1", "1").setSource("field", "2010-01-05T02:00").execute().actionGet(); client().prepareIndex("test", "type1", "1").setSource("field", "2010-01-05T02:00").execute().actionGet();
client().prepareIndex("test", "type1", "2").setSource("field", "2010-01-06T02:00").execute().actionGet(); client().prepareIndex("test", "type1", "2").setSource("field", "2010-01-06T02:00").execute().actionGet();
refresh();
ensureGreen(); ensureGreen();
refresh();
// test include upper on ranges to include the full day on the upper bound (disabled here though...) // test include upper on ranges to include the full day on the upper bound (disabled here though...)
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.rangeQuery("field").gte("2010-01-05").lte("2010-01-06")).execute().actionGet(); SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.rangeQuery("field").gte("2010-01-05").lte("2010-01-06")).execute().actionGet();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
@ -130,8 +129,8 @@ public class SimpleSearchTests extends AbstractSharedClusterTest {
prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder()).execute().actionGet(); prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder()).execute().actionGet();
client().prepareIndex("test", "type1", "1").setSource("field", "2010-01-05T02:00").execute().actionGet(); client().prepareIndex("test", "type1", "1").setSource("field", "2010-01-05T02:00").execute().actionGet();
client().prepareIndex("test", "type1", "2").setSource("field", "2010-01-06T02:00").execute().actionGet(); client().prepareIndex("test", "type1", "2").setSource("field", "2010-01-06T02:00").execute().actionGet();
refresh();
ensureGreen(); ensureGreen();
refresh();
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.rangeQuery("field").gte("2010-01-03||+2d").lte("2010-01-04||+2d")).execute().actionGet(); SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.rangeQuery("field").gte("2010-01-03||+2d").lte("2010-01-04||+2d")).execute().actionGet();
assertNoFailures(searchResponse); assertNoFailures(searchResponse);
assertThat(searchResponse.getHits().totalHits(), equalTo(2l)); assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
@ -139,39 +138,39 @@ public class SimpleSearchTests extends AbstractSharedClusterTest {
searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryString("field:[2010-01-03||+2d TO 2010-01-04||+2d]")).execute().actionGet(); searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryString("field:[2010-01-03||+2d TO 2010-01-04||+2d]")).execute().actionGet();
assertThat(searchResponse.getHits().totalHits(), equalTo(2l)); assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
} }
@Test @Test
public void localDependentDateTests() throws Exception { public void localDependentDateTests() throws Exception {
prepareCreate("test") prepareCreate("test")
.addMapping("type1", .addMapping("type1",
jsonBuilder().startObject() jsonBuilder().startObject()
.startObject("type1") .startObject("type1")
.startObject("properties") .startObject("properties")
.startObject("date_field") .startObject("date_field")
.field("type", "date") .field("type", "date")
.field("format", "E, d MMM yyyy HH:mm:ss Z") .field("format", "E, d MMM yyyy HH:mm:ss Z")
.field("locale", "de") .field("locale", "de")
.endObject() .endObject()
.endObject() .endObject()
.endObject() .endObject()
.endObject()) .endObject())
.execute().actionGet(); .execute().actionGet();
ensureGreen(); ensureGreen();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
client().prepareIndex("test", "type1", ""+i).setSource("date_field", "Mi, 06 Dez 2000 02:55:00 -0800").execute().actionGet(); client().prepareIndex("test", "type1", "" + i).setSource("date_field", "Mi, 06 Dez 2000 02:55:00 -0800").execute().actionGet();
client().prepareIndex("test", "type1", ""+(10+i)).setSource("date_field", "Do, 07 Dez 2000 02:55:00 -0800").execute().actionGet(); client().prepareIndex("test", "type1", "" + (10 + i)).setSource("date_field", "Do, 07 Dez 2000 02:55:00 -0800").execute().actionGet();
} }
client().admin().indices().prepareRefresh().execute().actionGet(); client().admin().indices().prepareRefresh().execute().actionGet();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
SearchResponse searchResponse = client().prepareSearch("test") SearchResponse searchResponse = client().prepareSearch("test")
.setQuery(QueryBuilders.rangeQuery("date_field").gte("Di, 05 Dez 2000 02:55:00 -0800").lte("Do, 07 Dez 2000 00:00:00 -0800")) .setQuery(QueryBuilders.rangeQuery("date_field").gte("Di, 05 Dez 2000 02:55:00 -0800").lte("Do, 07 Dez 2000 00:00:00 -0800"))
.execute().actionGet(); .execute().actionGet();
assertThat(searchResponse.getHits().totalHits(), equalTo(10l)); assertThat(searchResponse.getHits().totalHits(), equalTo(10l));
searchResponse = client().prepareSearch("test") searchResponse = client().prepareSearch("test")
.setQuery(QueryBuilders.rangeQuery("date_field").gte( "Di, 05 Dez 2000 02:55:00 -0800").lte("Fr, 08 Dez 2000 00:00:00 -0800")) .setQuery(QueryBuilders.rangeQuery("date_field").gte("Di, 05 Dez 2000 02:55:00 -0800").lte("Fr, 08 Dez 2000 00:00:00 -0800"))
.execute().actionGet(); .execute().actionGet();
assertThat(searchResponse.getHits().totalHits(), equalTo(20l)); assertThat(searchResponse.getHits().totalHits(), equalTo(20l));
} }
} }