|
@@ -20,6 +20,7 @@
|
|
|
package org.elasticsearch.routing;
|
|
|
|
|
|
import org.elasticsearch.ElasticsearchException;
|
|
|
+import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.action.RoutingMissingException;
|
|
|
import org.elasticsearch.action.admin.indices.alias.Alias;
|
|
|
import org.elasticsearch.action.explain.ExplainResponse;
|
|
@@ -30,6 +31,9 @@ import org.elasticsearch.action.termvectors.TermVectorsRequest;
|
|
|
import org.elasticsearch.action.termvectors.TermVectorsResponse;
|
|
|
import org.elasticsearch.action.update.UpdateResponse;
|
|
|
import org.elasticsearch.client.Requests;
|
|
|
+import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|
|
+import org.elasticsearch.common.settings.ImmutableSettings;
|
|
|
+import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
|
import org.elasticsearch.index.mapper.MapperParsingException;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
@@ -40,17 +44,13 @@ import org.junit.Test;
|
|
|
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
|
|
import static org.hamcrest.Matchers.*;
|
|
|
|
|
|
-/**
|
|
|
- *
|
|
|
- */
|
|
|
public class SimpleRoutingTests extends ElasticsearchIntegrationTest {
|
|
|
|
|
|
@Override
|
|
|
protected int minimumNumberOfShards() {
|
|
|
return 2;
|
|
|
}
|
|
|
-
|
|
|
- @Test
|
|
|
+
|
|
|
public void testSimpleCrudRouting() throws Exception {
|
|
|
createIndex("test");
|
|
|
ensureGreen();
|
|
@@ -107,8 +107,7 @@ public class SimpleRoutingTests extends ElasticsearchIntegrationTest {
|
|
|
assertThat(client().prepareGet("test", "type1", "1").setRouting("0").execute().actionGet().isExists(), equalTo(false));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- @Test
|
|
|
+
|
|
|
public void testSimpleSearchRouting() {
|
|
|
createIndex("test");
|
|
|
ensureGreen();
|
|
@@ -174,8 +173,7 @@ public class SimpleRoutingTests extends ElasticsearchIntegrationTest {
|
|
|
assertThat(client().prepareCount().setRouting("0", "1", "0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(2l));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- @Test
|
|
|
+
|
|
|
public void testRequiredRoutingMapping() throws Exception {
|
|
|
client().admin().indices().prepareCreate("test").addAlias(new Alias("alias"))
|
|
|
.addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("_routing").field("required", true).endObject().endObject().endObject())
|
|
@@ -230,8 +228,7 @@ public class SimpleRoutingTests extends ElasticsearchIntegrationTest {
|
|
|
assertThat(client().prepareGet(indexOrAlias(), "type1", "1").setRouting("0").execute().actionGet().isExists(), equalTo(false));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- @Test
|
|
|
+
|
|
|
public void testRequiredRoutingWithPathMapping() throws Exception {
|
|
|
client().admin().indices().prepareCreate("test")
|
|
|
.addAlias(new Alias("alias"))
|
|
@@ -239,6 +236,7 @@ public class SimpleRoutingTests extends ElasticsearchIntegrationTest {
|
|
|
.startObject("_routing").field("required", true).field("path", "routing_field").endObject().startObject("properties")
|
|
|
.startObject("routing_field").field("type", "string").field("index", randomBoolean() ? "no" : "not_analyzed").field("doc_values", randomBoolean() ? "yes" : "no").endObject().endObject()
|
|
|
.endObject().endObject())
|
|
|
+ .setSettings(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2_ID)
|
|
|
.execute().actionGet();
|
|
|
ensureGreen();
|
|
|
|
|
@@ -269,14 +267,14 @@ public class SimpleRoutingTests extends ElasticsearchIntegrationTest {
|
|
|
assertThat(client().prepareGet(indexOrAlias(), "type1", "1").setRouting("0").execute().actionGet().isExists(), equalTo(true));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- @Test
|
|
|
+
|
|
|
public void testRequiredRoutingWithPathMappingBulk() throws Exception {
|
|
|
client().admin().indices().prepareCreate("test")
|
|
|
.addAlias(new Alias("alias"))
|
|
|
.addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1")
|
|
|
.startObject("_routing").field("required", true).field("path", "routing_field").endObject()
|
|
|
.endObject().endObject())
|
|
|
+ .setSettings(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2_ID)
|
|
|
.execute().actionGet();
|
|
|
ensureGreen();
|
|
|
|
|
@@ -301,14 +299,44 @@ public class SimpleRoutingTests extends ElasticsearchIntegrationTest {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
- public void testRequiredRoutingWithPathNumericType() throws Exception {
|
|
|
+ public void testRequiredRoutingBulk() throws Exception {
|
|
|
+ client().admin().indices().prepareCreate("test")
|
|
|
+ .addAlias(new Alias("alias"))
|
|
|
+ .addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1")
|
|
|
+ .startObject("_routing").field("required", true).endObject()
|
|
|
+ .endObject().endObject())
|
|
|
+ .execute().actionGet();
|
|
|
+ ensureGreen();
|
|
|
+
|
|
|
+ logger.info("--> indexing with id [1], and routing [0]");
|
|
|
+ client().prepareBulk().add(
|
|
|
+ client().prepareIndex(indexOrAlias(), "type1", "1").setRouting("0").setSource("field", "value1")).execute().actionGet();
|
|
|
+ client().admin().indices().prepareRefresh().execute().actionGet();
|
|
|
|
|
|
+ logger.info("--> verifying get with no routing, should fail");
|
|
|
+ for (int i = 0; i < 5; i++) {
|
|
|
+ try {
|
|
|
+ client().prepareGet(indexOrAlias(), "type1", "1").execute().actionGet().isExists();
|
|
|
+ fail();
|
|
|
+ } catch (RoutingMissingException e) {
|
|
|
+ assertThat(e.status(), equalTo(RestStatus.BAD_REQUEST));
|
|
|
+ assertThat(e.getMessage(), equalTo("routing is required for [test]/[type1]/[1]"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logger.info("--> verifying get with routing, should find");
|
|
|
+ for (int i = 0; i < 5; i++) {
|
|
|
+ assertThat(client().prepareGet(indexOrAlias(), "type1", "1").setRouting("0").execute().actionGet().isExists(), equalTo(true));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testRequiredRoutingWithPathNumericType() throws Exception {
|
|
|
+
|
|
|
client().admin().indices().prepareCreate("test")
|
|
|
.addAlias(new Alias("alias"))
|
|
|
.addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1")
|
|
|
.startObject("_routing").field("required", true).field("path", "routing_field").endObject()
|
|
|
.endObject().endObject())
|
|
|
+ .setSettings(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2_ID)
|
|
|
.execute().actionGet();
|
|
|
ensureGreen();
|
|
|
|
|
@@ -331,8 +359,7 @@ public class SimpleRoutingTests extends ElasticsearchIntegrationTest {
|
|
|
assertThat(client().prepareGet(indexOrAlias(), "type1", "1").setRouting("0").execute().actionGet().isExists(), equalTo(true));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- @Test
|
|
|
+
|
|
|
public void testRequiredRoutingMapping_variousAPIs() throws Exception {
|
|
|
client().admin().indices().prepareCreate("test").addAlias(new Alias("alias"))
|
|
|
.addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("_routing").field("required", true).endObject().endObject().endObject())
|