diff --git a/src/test/java/org/elasticsearch/gateway/local/SimpleRecoveryLocalGatewayTests.java b/src/test/java/org/elasticsearch/gateway/local/SimpleRecoveryLocalGatewayTests.java index bc69288c5ee6e..0cdec3a3c6cab 100644 --- a/src/test/java/org/elasticsearch/gateway/local/SimpleRecoveryLocalGatewayTests.java +++ b/src/test/java/org/elasticsearch/gateway/local/SimpleRecoveryLocalGatewayTests.java @@ -51,10 +51,10 @@ /** * */ -@ClusterScope(numNodes=0, scope=Scope.TEST) +@ClusterScope(numNodes = 0, scope = Scope.TEST) public class SimpleRecoveryLocalGatewayTests extends AbstractIntegrationTest { - + private ImmutableSettings.Builder settingsBuilder() { return ImmutableSettings.settingsBuilder().put("gateway.type", "local"); } @@ -237,7 +237,7 @@ public Settings onNodeStopped(String nodeName) throws Exception { public boolean clearData(String nodeName) { return firstNode.equals(nodeName); } - + }); logger.info("Running Cluster Health (wait for the shards to startup)"); @@ -290,7 +290,7 @@ public void doAfterNodes(int numNodes, Client client) throws Exception { logger.info("--> add some metadata, additional type and template"); client.admin().indices().preparePutMapping("test").setType("type2") - .setSource(jsonBuilder().startObject().startObject("type1").startObject("_source").field("enabled", false).endObject().endObject().endObject()) + .setSource(jsonBuilder().startObject().startObject("type2").startObject("_source").field("enabled", false).endObject().endObject().endObject()) .execute().actionGet(); client.admin().indices().preparePutTemplate("template_1") .setTemplate("te*") @@ -303,9 +303,9 @@ public void doAfterNodes(int numNodes, Client client) throws Exception { client.admin().indices().prepareAliases().addAlias("test", "test_alias", FilterBuilders.termFilter("field", "value")).execute().actionGet(); logger.info("--> starting two nodes back, verifying we got the latest version"); } - + } - + }); logger.info("--> running cluster_health (wait for the shards to startup)"); @@ -333,7 +333,7 @@ public void testReusePeerRecovery() throws Exception { ImmutableSettings.Builder settings = settingsBuilder() .put("action.admin.cluster.node.shutdown.delay", "10ms") .put("gateway.recover_after_nodes", 4) - + .put(BalancedShardsAllocator.SETTING_THRESHOLD, 1.1f); // use less agressive settings cluster().startNode(settings); diff --git a/src/test/java/org/elasticsearch/get/GetActionTests.java b/src/test/java/org/elasticsearch/get/GetActionTests.java index 3627a25267c65..d87702a832f34 100644 --- a/src/test/java/org/elasticsearch/get/GetActionTests.java +++ b/src/test/java/org/elasticsearch/get/GetActionTests.java @@ -60,7 +60,7 @@ public void simpleGetTests() { response = client().prepareGet("test", "type1", "1").setFields(Strings.EMPTY_ARRAY).execute().actionGet(); assertThat(response.isExists(), equalTo(true)); assertThat(response.getSourceAsBytes(), nullValue()); - + logger.info("--> realtime get 1 (no type)"); response = client().prepareGet("test", null, "1").execute().actionGet(); assertThat(response.isExists(), equalTo(true)); @@ -200,8 +200,8 @@ public void realtimeGetWithCompress() throws Exception { public void getFieldsWithDifferentTypes() throws Exception { client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.refresh_interval", -1)) - .addMapping("type1", jsonBuilder().startObject().startObject("type").startObject("_source").field("enabled", true).endObject().endObject().endObject()) - .addMapping("type2", jsonBuilder().startObject().startObject("type") + .addMapping("type1", jsonBuilder().startObject().startObject("type1").startObject("_source").field("enabled", true).endObject().endObject().endObject()) + .addMapping("type2", jsonBuilder().startObject().startObject("type2") .startObject("_source").field("enabled", false).endObject() .startObject("properties") .startObject("str").field("type", "string").field("store", "yes").endObject() @@ -374,13 +374,13 @@ public void testThatGetFromTranslogShouldWorkWithExclude() throws Exception { String mapping = jsonBuilder() .startObject() - .startObject("source_excludes") - .startObject("_source") - .array("excludes", "excluded") - .endObject() - .endObject() + .startObject(type) + .startObject("_source") + .array("excludes", "excluded") + .endObject() .endObject() - .string(); + .endObject() + .string(); client().admin().indices().prepareCreate(index) .addMapping(type, mapping) @@ -408,14 +408,14 @@ public void testThatGetFromTranslogShouldWorkWithInclude() throws Exception { String type = "type1"; String mapping = jsonBuilder() - .startObject() - .startObject("source_excludes") - .startObject("_source") - .array("includes", "included") - .endObject() + .startObject() + .startObject(type) + .startObject("_source") + .array("includes", "included") + .endObject() .endObject() - .endObject() - .string(); + .endObject() + .string(); client().admin().indices().prepareCreate(index) .addMapping(type, mapping) @@ -443,15 +443,15 @@ public void testThatGetFromTranslogShouldWorkWithIncludeExcludeAndFields() throw String type = "type1"; String mapping = jsonBuilder() - .startObject() - .startObject("source_excludes") - .startObject("_source") - .array("includes", "included") - .array("exlcudes", "excluded") - .endObject() + .startObject() + .startObject(type) + .startObject("_source") + .array("includes", "included") + .array("exlcudes", "excluded") + .endObject() .endObject() - .endObject() - .string(); + .endObject() + .string(); client().admin().indices().prepareCreate(index) .addMapping(type, mapping) @@ -463,7 +463,7 @@ public void testThatGetFromTranslogShouldWorkWithIncludeExcludeAndFields() throw .field("field", "1", "2") .field("included", "should be seen") .field("excluded", "should not be seen") - .endObject()) + .endObject()) .execute().actionGet(); GetResponse responseBeforeFlush = client().prepareGet(index, type, "1").setFields("_source", "included", "excluded").execute().actionGet(); @@ -476,6 +476,7 @@ public void testThatGetFromTranslogShouldWorkWithIncludeExcludeAndFields() throw assertThat(responseBeforeFlush.getSourceAsMap(), not(hasKey("field"))); assertThat(responseBeforeFlush.getSourceAsMap(), hasKey("included")); assertThat(responseBeforeFlush.getSourceAsString(), is(responseAfterFlush.getSourceAsString())); + } } diff --git a/src/test/java/org/elasticsearch/index/mapper/source/DefaultSourceMappingTests.java b/src/test/java/org/elasticsearch/index/mapper/source/DefaultSourceMappingTests.java index 3662b09ff19d5..adc3892e3d2f5 100644 --- a/src/test/java/org/elasticsearch/index/mapper/source/DefaultSourceMappingTests.java +++ b/src/test/java/org/elasticsearch/index/mapper/source/DefaultSourceMappingTests.java @@ -150,14 +150,14 @@ public void testDefaultMappingAndNoMapping() throws Exception { // all is well } } - + @Test public void testDefaultMappingAndWithMappingOverride() throws Exception { String defaultMapping = XContentFactory.jsonBuilder().startObject().startObject(MapperService.DEFAULT_MAPPING) .startObject("_source").field("enabled", false).endObject() .endObject().endObject().string(); - String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") + String mapping = XContentFactory.jsonBuilder().startObject().startObject("my_type") .startObject("_source").field("enabled", true).endObject() .endObject().endObject().string(); @@ -189,7 +189,7 @@ public void testDefaultMappingAndWithMappingOverrideWithMapperService() throws E MapperService mapperService = MapperTestUtils.newMapperService(); mapperService.merge(MapperService.DEFAULT_MAPPING, defaultMapping, true); - String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") + String mapping = XContentFactory.jsonBuilder().startObject().startObject("my_type") .startObject("_source").field("enabled", true).endObject() .endObject().endObject().string(); mapperService.merge("my_type", mapping, true); diff --git a/src/test/java/org/elasticsearch/search/child/SimpleChildQuerySearchTests.java b/src/test/java/org/elasticsearch/search/child/SimpleChildQuerySearchTests.java index 5850675ba3c8f..077f7a235f51b 100644 --- a/src/test/java/org/elasticsearch/search/child/SimpleChildQuerySearchTests.java +++ b/src/test/java/org/elasticsearch/search/child/SimpleChildQuerySearchTests.java @@ -74,14 +74,14 @@ public void multiLevelChild() throws Exception { .preparePutMapping("test") .setType("child") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); client().admin() .indices() .preparePutMapping("test") .setType("grandchild") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "child").endObject() + jsonBuilder().startObject().startObject("grandchild").startObject("_parent").field("type", "child").endObject() .endObject().endObject()).execute().actionGet(); client().prepareIndex("test", "parent", "p1").setSource("p_field", "p_value1").execute().actionGet(); @@ -144,7 +144,7 @@ public void test2744() throws ElasticSearchException, IOException { .preparePutMapping("test") .setType("test") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "foo").endObject().endObject() + jsonBuilder().startObject().startObject("test").startObject("_parent").field("type", "foo").endObject().endObject() .endObject()).execute().actionGet(); // index simple data @@ -170,7 +170,7 @@ public void simpleChildQuery() throws Exception { .preparePutMapping("test") .setType("child") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); // index simple data @@ -290,7 +290,7 @@ public void testClearIdCacheBug() throws Exception { assertThat(indicesStatsResponse.getTotal().getIdCache().getMemorySizeInBytes(), equalTo(0l)); // Now add mapping + children - client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("type") + client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("child") .startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); @@ -336,7 +336,7 @@ public void testCachingBug_withFqueryFilter() throws Exception { .preparePutMapping("test") .setType("child") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); // index simple data @@ -380,7 +380,7 @@ public void testHasParentFilter() throws Exception { .preparePutMapping("test") .setType("child") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); Map> parentToChildren = newHashMap(); @@ -440,7 +440,7 @@ public void simpleChildQueryWithFlush() throws Exception { .preparePutMapping("test") .setType("child") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); // index simple data with flushes, so we have many segments @@ -548,7 +548,7 @@ public void simpleChildQueryWithFlushAnd3Shards() throws Exception { .preparePutMapping("test") .setType("child") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); // index simple data with flushes, so we have many segments @@ -656,7 +656,7 @@ public void testScopedFacet() throws Exception { .preparePutMapping("test") .setType("child") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); // index simple data @@ -703,7 +703,7 @@ public void testDeletedParent() throws Exception { .preparePutMapping("test") .setType("child") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); // index simple data @@ -773,7 +773,7 @@ public void testDfsSearchType() throws Exception { .preparePutMapping("test") .setType("child") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); // index simple data @@ -813,7 +813,7 @@ public void testFixAOBEIfTopChildrenIsWrappedInMusNotClause() throws Exception { .preparePutMapping("test") .setType("child") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); // index simple data @@ -844,7 +844,7 @@ public void testTopChildrenReSearchBug() throws Exception { .preparePutMapping("test") .setType("child") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); int numberOfParents = 4; @@ -889,7 +889,7 @@ public void testHasChildAndHasParentFailWhenSomeSegmentsDontContainAnyParentOrCh .preparePutMapping("test") .setType("child") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); client().prepareIndex("test", "parent", "1").setSource("p_field", 1).execute().actionGet(); @@ -923,7 +923,7 @@ public void testCountApiUsage() throws Exception { .preparePutMapping("test") .setType("child") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); String parentId = "p1"; @@ -963,7 +963,7 @@ public void testExplainUsage() throws Exception { .preparePutMapping("test") .setType("child") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); String parentId = "p1"; @@ -1007,11 +1007,11 @@ public void testScoreForParentChildQueries() throws Exception { .prepareCreate("test") .addMapping( "child", - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()) .addMapping( "child1", - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child1").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()) .setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0)) .execute().actionGet(); @@ -1115,7 +1115,7 @@ List createDocBuilders() { .setSource("c_field1", 1, "c_field2", 1).setParent("2")); indexBuilders.add(client().prepareIndex().setType("child").setId("9").setIndex("test") .setSource("c_field1", 1, "c_field2", 1).setParent("p")); // why - // "p"???? + // "p"???? indexBuilders.add(client().prepareIndex().setType("child").setId("10").setIndex("test") .setSource("c_field1", 1, "c_field2", 1).setParent("2")); indexBuilders.add(client().prepareIndex().setType("child").setId("11").setIndex("test") @@ -1133,7 +1133,7 @@ List createDocBuilders() { .setSource("c_field1", 1, "c_field2", 1, "c_field3", 1).setParent("3")); indexBuilders.add(client().prepareIndex().setType("child").setId("15").setIndex("test") .setSource("c_field1", 1, "c_field2", 2, "c_field3", 2).setParent("3")); // why - // "p"???? + // "p"???? indexBuilders.add(client().prepareIndex().setType("child").setId("16").setIndex("test") .setSource("c_field1", 1, "c_field2", 2, "c_field3", 3).setParent("3")); indexBuilders.add(client().prepareIndex().setType("child").setId("17").setIndex("test") @@ -1154,11 +1154,11 @@ public void testScoreForParentChildQueries_withFunctionScore() throws Exception .prepareCreate("test") .addMapping( "child", - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()) .addMapping( "child1", - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child1").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()) .setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0)) .execute().actionGet(); @@ -1295,7 +1295,7 @@ public void testHasChildAndHasParentFilter_withFilter() throws Exception { .preparePutMapping("test") .setType("child") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); client().prepareIndex("test", "parent", "1").setSource("p_field", 1).execute().actionGet(); @@ -1332,7 +1332,7 @@ public void testSimpleQueryRewrite() throws Exception { .preparePutMapping("test") .setType("child") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); // index simple data @@ -1349,7 +1349,7 @@ public void testSimpleQueryRewrite() throws Exception { } client().admin().indices().prepareRefresh().execute().actionGet(); - SearchType[] searchTypes = new SearchType[] { SearchType.QUERY_THEN_FETCH, SearchType.DFS_QUERY_THEN_FETCH }; + SearchType[] searchTypes = new SearchType[]{SearchType.QUERY_THEN_FETCH, SearchType.DFS_QUERY_THEN_FETCH}; for (SearchType searchType : searchTypes) { SearchResponse searchResponse = client().prepareSearch("test").setSearchType(searchType) .setQuery(hasChildQuery("child", prefixQuery("c_field", "c")).scoreType("max")).addSort("p_field", SortOrder.ASC) @@ -1400,7 +1400,7 @@ public void testReIndexingParentAndChildDocuments() throws Exception { .preparePutMapping("test") .setType("child") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); // index simple data @@ -1475,7 +1475,7 @@ public void testHasChildQueryWithMinimumScore() throws Exception { .preparePutMapping("test") .setType("child") .setSource( - jsonBuilder().startObject().startObject("type").startObject("_parent").field("type", "parent").endObject() + jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); // index simple data @@ -1518,7 +1518,7 @@ public void testParentFieldFilter() throws Exception { .preparePutMapping("test") .setType("child2") .setSource( - jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent2").endObject() + jsonBuilder().startObject().startObject("child2").startObject("_parent").field("type", "parent2").endObject() .endObject().endObject()).execute().actionGet(); // test term filter @@ -1587,7 +1587,7 @@ public void testHasChildNotBeingCached() throws ElasticSearchException, IOExcept .put("index.number_of_replicas", 0) ).execute().actionGet(); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); - client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("type") + client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("child") .startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); @@ -1632,7 +1632,7 @@ public void testDeleteByQuery_has_child() throws Exception { .put("index.refresh_interval", "-1") ).execute().actionGet(); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); - client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("type") + client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("child") .startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); @@ -1678,7 +1678,7 @@ public void testDeleteByQuery_has_child_SingleRefresh() throws Exception { .put("index.refresh_interval", "-1") ).execute().actionGet(); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); - client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("type") + client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("child") .startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); @@ -1734,7 +1734,7 @@ public void testDeleteByQuery_has_parent() throws Exception { .put("index.refresh_interval", "-1") ).execute().actionGet(); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); - client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("type") + client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("child") .startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); @@ -1848,7 +1848,7 @@ public void indexChildDocWithNoParentMapping() throws ElasticSearchException, IO ).execute().actionGet(); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); client().admin().indices().preparePutMapping("test").setType("child1").setSource( - jsonBuilder().startObject().startObject("type").endObject().endObject() + jsonBuilder().startObject().startObject("child1").endObject().endObject() ).execute().actionGet(); client().prepareIndex("test", "parent", "p1").setSource("p_field", "p_value1", "_parent", "bla").execute().actionGet(); @@ -1884,7 +1884,7 @@ public void testAddingParentToExistingMapping() throws ElasticSearchException, I try { // Adding _parent metadata field to existing mapping is prohibited: - client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("type") + client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("child") .startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); fail(); @@ -1903,7 +1903,7 @@ public void testTopChildrenBug_concurrencyIssue() throws Exception { .put("index.number_of_replicas", 0) ).execute().actionGet(); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); - client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("type") + client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("child") .startObject("_parent").field("type", "parent").endObject() .endObject().endObject()).execute().actionGet(); diff --git a/src/test/java/org/elasticsearch/search/fields/SearchFieldsTests.java b/src/test/java/org/elasticsearch/search/fields/SearchFieldsTests.java index 145c6d40fb5de..9680f2be75fe3 100644 --- a/src/test/java/org/elasticsearch/search/fields/SearchFieldsTests.java +++ b/src/test/java/org/elasticsearch/search/fields/SearchFieldsTests.java @@ -48,7 +48,7 @@ * */ public class SearchFieldsTests extends AbstractIntegrationTest { - + @Override public Settings getSettings() { return randomSettingsBuilder() @@ -62,7 +62,7 @@ public void testStoredFields() throws Exception { createIndex("test"); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet(); - String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties") .startObject("field1").field("type", "string").field("store", "yes").endObject() .startObject("field2").field("type", "string").field("store", "no").endObject() .startObject("field3").field("type", "string").field("store", "yes").endObject() @@ -119,7 +119,7 @@ public void testScriptDocAndFields() throws Exception { createIndex("test"); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet(); - String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties") .startObject("num1").field("type", "double").field("store", "yes").endObject() .endObject().endObject().endObject().string(); @@ -272,7 +272,7 @@ public void testStoredFieldsWithoutSource() throws Exception { createIndex("test"); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet(); - String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties") .startObject("_source").field("enabled", false).endObject() .startObject("byte_field").field("type", "byte").field("store", "yes").endObject() .startObject("short_field").field("type", "short").field("store", "yes").endObject() diff --git a/src/test/java/org/elasticsearch/search/query/SimpleQueryTests.java b/src/test/java/org/elasticsearch/search/query/SimpleQueryTests.java index 5fdd587b68922..f8204b0c35f2e 100644 --- a/src/test/java/org/elasticsearch/search/query/SimpleQueryTests.java +++ b/src/test/java/org/elasticsearch/search/query/SimpleQueryTests.java @@ -119,7 +119,7 @@ public void testIndexOptions() throws Exception { assertTrue("wrong exception message " + e.getMessage(), e.getMessage().endsWith("IllegalStateException[field \"field1\" was indexed without position data; cannot run PhraseQuery (term=quick)]; }")); } } - + @Test // see #3521 public void testConstantScoreQuery() throws Exception { Random random = getRandom(); @@ -132,29 +132,29 @@ public void testConstantScoreQuery() throws Exception { for (SearchHit searchHit : hits) { assertThat(searchHit.getScore(), equalTo(1.0f)); } - + searchResponse = client().prepareSearch("test").setQuery( QueryBuilders.boolQuery().must(QueryBuilders.matchAllQuery()).must( - QueryBuilders.constantScoreQuery(QueryBuilders.matchQuery("field1", "quick")).boost(1.0f + getRandom().nextFloat()))).get(); + QueryBuilders.constantScoreQuery(QueryBuilders.matchQuery("field1", "quick")).boost(1.0f + getRandom().nextFloat()))).get(); hits = searchResponse.getHits(); assertThat(hits.totalHits(), equalTo(2l)); assertThat(hits.getAt(0).score(), equalTo(hits.getAt(1).score())); - + client().prepareSearch("test").setQuery(QueryBuilders.constantScoreQuery(QueryBuilders.matchQuery("field1", "quick")).boost(1.0f + getRandom().nextFloat())).get(); hits = searchResponse.getHits(); assertThat(hits.totalHits(), equalTo(2l)); assertThat(hits.getAt(0).score(), equalTo(hits.getAt(1).score())); - + searchResponse = client().prepareSearch("test").setQuery( QueryBuilders.constantScoreQuery(QueryBuilders.boolQuery().must(QueryBuilders.matchAllQuery()).must( - QueryBuilders.constantScoreQuery(QueryBuilders.matchQuery("field1", "quick")).boost(1.0f + (random.nextBoolean()? 0.0f : random.nextFloat()))))).get(); + QueryBuilders.constantScoreQuery(QueryBuilders.matchQuery("field1", "quick")).boost(1.0f + (random.nextBoolean() ? 0.0f : random.nextFloat()))))).get(); hits = searchResponse.getHits(); assertThat(hits.totalHits(), equalTo(2l)); assertThat(hits.getAt(0).score(), equalTo(hits.getAt(1).score())); for (SearchHit searchHit : hits) { assertThat(searchHit.getScore(), equalTo(1.0f)); } - + int num = atLeast(100); IndexRequestBuilder[] builders = new IndexRequestBuilder[num]; for (int i = 0; i < builders.length; i++) { @@ -175,13 +175,13 @@ public void testConstantScoreQuery() throws Exception { if (random.nextBoolean()) { searchResponse = client().prepareSearch("test_1").setQuery( QueryBuilders.boolQuery().must(QueryBuilders.matchAllQuery()).must( - QueryBuilders.constantScoreQuery(matchQuery).boost(1.0f + (random.nextBoolean()? 0.0f : random.nextFloat())))).setSize(num).get(); - hits = searchResponse.getHits(); + QueryBuilders.constantScoreQuery(matchQuery).boost(1.0f + (random.nextBoolean() ? 0.0f : random.nextFloat())))).setSize(num).get(); + hits = searchResponse.getHits(); } else { FilterBuilder filter = FilterBuilders.queryFilter(matchQuery); searchResponse = client().prepareSearch("test_1").setQuery( QueryBuilders.boolQuery().must(QueryBuilders.matchAllQuery()).must( - QueryBuilders.constantScoreQuery(filter).boost(1.0f + (random.nextBoolean()? 0.0f : random.nextFloat())))).setSize(num).get(); + QueryBuilders.constantScoreQuery(filter).boost(1.0f + (random.nextBoolean() ? 0.0f : random.nextFloat())))).setSize(num).get(); hits = searchResponse.getHits(); } assertThat(hits.totalHits(), equalTo(totalHits)); @@ -193,13 +193,13 @@ public void testConstantScoreQuery() throws Exception { } } } - + @Test // see #3521 public void testAllDocsQueryString() throws InterruptedException, ExecutionException { client().admin().indices().prepareCreate("test") .setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_replicas", 0)).execute().actionGet(); indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("foo", "bar"), - client().prepareIndex("test", "type1", "2").setSource("foo", "bar") + client().prepareIndex("test", "type1", "2").setSource("foo", "bar") ); int iters = atLeast(100); for (int i = 0; i < iters; i++) { @@ -208,15 +208,15 @@ public void testAllDocsQueryString() throws InterruptedException, ExecutionExcep .execute().actionGet(); assertNoFailures(searchResponse); assertThat(searchResponse.getHits().totalHits(), equalTo(2l)); - + searchResponse = client().prepareSearch("test") .setQuery(QueryBuilders.boolQuery().must(QueryBuilders.matchAllQuery()).must( QueryBuilders.constantScoreQuery(QueryBuilders.matchAllQuery()))) .execute().actionGet(); assertNoFailures(searchResponse); assertThat(searchResponse.getHits().totalHits(), equalTo(2l)); - assertThat((double)searchResponse.getHits().getAt(0).score(), closeTo(Math.sqrt(2), 0.1)); - assertThat((double)searchResponse.getHits().getAt(1).score(),closeTo(Math.sqrt(2), 0.1)); + assertThat((double) searchResponse.getHits().getAt(0).score(), closeTo(Math.sqrt(2), 0.1)); + assertThat((double) searchResponse.getHits().getAt(1).score(), closeTo(Math.sqrt(2), 0.1)); } } @@ -881,7 +881,7 @@ public void testQuotedQueryStringWithBoost() throws InterruptedException, Execut float boost = 10.0f; client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet(); indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("important", "phrase match", "less_important", "nothing important"), - client().prepareIndex("test", "type1", "2").setSource("important", "nothing important", "less_important", "phrase match") + client().prepareIndex("test", "type1", "2").setSource("important", "nothing important", "less_important", "phrase match") ); SearchResponse searchResponse = client().prepareSearch() @@ -891,7 +891,7 @@ public void testQuotedQueryStringWithBoost() throws InterruptedException, Execut assertThat(searchResponse.getHits().totalHits(), equalTo(2l)); assertThat(searchResponse.getHits().getAt(0).id(), equalTo("1")); assertThat(searchResponse.getHits().getAt(1).id(), equalTo("2")); - assertThat((double)searchResponse.getHits().getAt(0).score(), closeTo(boost * searchResponse.getHits().getAt(1).score(), .1)); + assertThat((double) searchResponse.getHits().getAt(0).score(), closeTo(boost * searchResponse.getHits().getAt(1).score(), .1)); searchResponse = client().prepareSearch() .setQuery(queryString("\"phrase match\"").field("important", boost).field("less_important").useDisMax(false)) @@ -900,9 +900,9 @@ public void testQuotedQueryStringWithBoost() throws InterruptedException, Execut assertThat(searchResponse.getHits().totalHits(), equalTo(2l)); assertThat(searchResponse.getHits().getAt(0).id(), equalTo("1")); assertThat(searchResponse.getHits().getAt(1).id(), equalTo("2")); - assertThat((double)searchResponse.getHits().getAt(0).score(), closeTo(boost * searchResponse.getHits().getAt(1).score(), .1)); + assertThat((double) searchResponse.getHits().getAt(0).score(), closeTo(boost * searchResponse.getHits().getAt(1).score(), .1)); } - + @Test public void testSpecialRangeSyntaxInQueryString() { client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet(); @@ -957,10 +957,10 @@ public void testSpecialRangeSyntaxInQueryString() { @Test public void testEmptyTermsFilter() throws Exception { - assertAcked(prepareCreate("test").addMapping("type", + assertAcked(prepareCreate("test").addMapping("type", jsonBuilder().startObject().startObject("type").startObject("properties") - .startObject("term").field("type", "string").endObject() - .endObject().endObject().endObject())); + .startObject("term").field("type", "string").endObject() + .endObject().endObject().endObject())); ensureGreen(); client().prepareIndex("test", "type", "1").setSource("term", "1").execute().actionGet(); client().prepareIndex("test", "type", "2").setSource("term", "2").execute().actionGet(); @@ -982,19 +982,19 @@ public void testEmptyTermsFilter() throws Exception { @Test public void testTermsLookupFilter() throws Exception { - assertAcked(prepareCreate("lookup").addMapping("type", + assertAcked(prepareCreate("lookup").addMapping("type", jsonBuilder().startObject().startObject("type").startObject("properties") - .startObject("terms").field("type", "string").endObject() - .startObject("other").field("type", "string").endObject() - .endObject().endObject().endObject())); - assertAcked(prepareCreate("lookup2").addMapping("type", + .startObject("terms").field("type", "string").endObject() + .startObject("other").field("type", "string").endObject() + .endObject().endObject().endObject())); + assertAcked(prepareCreate("lookup2").addMapping("type", jsonBuilder().startObject().startObject("type").startObject("properties") - .startObject("arr").startObject("properties").startObject("term").field("type", "string") - .endObject().endObject().endObject().endObject().endObject().endObject())); - assertAcked(prepareCreate("test").addMapping("type", + .startObject("arr").startObject("properties").startObject("term").field("type", "string") + .endObject().endObject().endObject().endObject().endObject().endObject())); + assertAcked(prepareCreate("test").addMapping("type", jsonBuilder().startObject().startObject("type").startObject("properties") - .startObject("term").field("type", "string").endObject() - .endObject().endObject().endObject())); + .startObject("term").field("type", "string").endObject() + .endObject().endObject().endObject())); ensureGreen(); client().prepareIndex("lookup", "type", "1").setSource("terms", new String[]{"1", "3"}).execute().actionGet(); client().prepareIndex("lookup", "type", "2").setSource("terms", new String[]{"2"}).execute().actionGet(); @@ -1581,41 +1581,41 @@ public void testSimpleDFSQuery() throws ElasticSearchException, IOException { .put("index.number_of_replicas", 0) ).addMapping("s", jsonBuilder() .startObject() - .startObject("s") - .startObject("_routing") - .field("required", true) - .field("path", "bs") - .endObject() - .startObject("properties") - .startObject("online") - .field("type", "boolean") - .endObject() - .startObject("ts") - .field("type", "date") - .field("ignore_malformed", false) - .field("format", "dateOptionalTime") - .endObject() - .startObject("bs") - .field("type", "string") - .field("index", "not_analyzed") - .endObject() - .endObject() - .endObject() + .startObject("s") + .startObject("_routing") + .field("required", true) + .field("path", "bs") + .endObject() + .startObject("properties") + .startObject("online") + .field("type", "boolean") + .endObject() + .startObject("ts") + .field("type", "date") + .field("ignore_malformed", false) + .field("format", "dateOptionalTime") + .endObject() + .startObject("bs") + .field("type", "string") + .field("index", "not_analyzed") + .endObject() + .endObject() + .endObject() .endObject()) .addMapping("bs", jsonBuilder() .startObject() - .startObject("s") - .startObject("properties") - .startObject("online") - .field("type", "boolean") - .endObject() - .startObject("ts") - .field("type", "date") - .field("ignore_malformed", false) - .field("format", "dateOptionalTime") - .endObject() - .endObject() - .endObject() + .startObject("bs") + .startObject("properties") + .startObject("online") + .field("type", "boolean") + .endObject() + .startObject("ts") + .field("type", "date") + .field("ignore_malformed", false) + .field("format", "dateOptionalTime") + .endObject() + .endObject() + .endObject() .endObject()) .execute().actionGet(); ensureGreen(); @@ -1690,7 +1690,7 @@ public void testMultiFieldQueryString() { assertHitCount(client().prepareSearch("test").setQuery(queryString("/value[01]/").field("field1").field("field2")).get(), 1); assertHitCount(client().prepareSearch("test").setQuery(queryString("field\\*:/value[01]/")).get(), 1); } - + // see #3881 - for extensive description of the issue @Test public void testMatchQueryWithSynonyms() throws IOException { @@ -1701,18 +1701,18 @@ public void testMatchQueryWithSynonyms() throws IOException { .put("index.analysis.analyzer.index.tokenizer", "standard") .put("index.analysis.analyzer.index.filter", "lowercase") .put("index.analysis.analyzer.search.type", "custom") - .put("index.analysis.analyzer.search.tokenizer", "standard") + .put("index.analysis.analyzer.search.tokenizer", "standard") .putArray("index.analysis.analyzer.search.filter", "lowercase", "synonym") .put("index.analysis.filter.synonym.type", "synonym") .putArray("index.analysis.filter.synonym.synonyms", "fast, quick")); - + XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("test") .startObject("properties") .startObject("text") - .field("type", "string") - .field("index_analyzer", "index") - .field("search_analyzer", "search") + .field("type", "string") + .field("index_analyzer", "index") + .field("search_analyzer", "search") .endObject() .endObject() .endObject().endObject(); @@ -1729,7 +1729,7 @@ public void testMatchQueryWithSynonyms() throws IOException { assertHitCount(searchResponse, 1); searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.matchQuery("text", "fast").operator(MatchQueryBuilder.Operator.AND)).get(); assertHitCount(searchResponse, 1); - + client().prepareIndex("test", "test", "2").setSource(jsonBuilder().startObject() .field("text", "fast brown fox") .endObject()) @@ -1740,7 +1740,7 @@ public void testMatchQueryWithSynonyms() throws IOException { searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.matchQuery("text", "quick brown").operator(MatchQueryBuilder.Operator.AND)).get(); assertHitCount(searchResponse, 2); } - + @Test public void testMatchQueryWithStackedStems() throws IOException { CreateIndexRequestBuilder builder = prepareCreate("test").setSettings(settingsBuilder() @@ -1754,13 +1754,13 @@ public void testMatchQueryWithStackedStems() throws IOException { .putArray("index.analysis.analyzer.search.filter", "lowercase", "keyword_repeat", "porterStem", "unique_stem") .put("index.analysis.filter.unique_stem.type", "unique") .put("index.analysis.filter.unique_stem.only_on_same_position", true)); - + XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("test") .startObject("properties") .startObject("text") - .field("type", "string") - .field("index_analyzer", "index") - .field("search_analyzer", "search") + .field("type", "string") + .field("index_analyzer", "index") + .field("search_analyzer", "search") .endObject() .endObject() .endObject().endObject(); @@ -1773,7 +1773,7 @@ public void testMatchQueryWithStackedStems() throws IOException { client().admin().indices().prepareRefresh().execute().actionGet(); SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.matchQuery("text", "fox runs").operator(MatchQueryBuilder.Operator.AND)).get(); assertHitCount(searchResponse, 1); - + client().prepareIndex("test", "test", "2").setSource(jsonBuilder().startObject() .field("text", "run fox run") .endObject()) @@ -1782,7 +1782,7 @@ public void testMatchQueryWithStackedStems() throws IOException { searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.matchQuery("text", "fox runs").operator(MatchQueryBuilder.Operator.AND)).get(); assertHitCount(searchResponse, 2); } - + @Test public void testQueryStringWithSynonyms() throws IOException { CreateIndexRequestBuilder builder = prepareCreate("test").setSettings(settingsBuilder() @@ -1792,18 +1792,18 @@ public void testQueryStringWithSynonyms() throws IOException { .put("index.analysis.analyzer.index.tokenizer", "standard") .put("index.analysis.analyzer.index.filter", "lowercase") .put("index.analysis.analyzer.search.type", "custom") - .put("index.analysis.analyzer.search.tokenizer", "standard") + .put("index.analysis.analyzer.search.tokenizer", "standard") .putArray("index.analysis.analyzer.search.filter", "lowercase", "synonym") .put("index.analysis.filter.synonym.type", "synonym") .putArray("index.analysis.filter.synonym.synonyms", "fast, quick")); - + XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("test") .startObject("properties") .startObject("text") - .field("type", "string") - .field("index_analyzer", "index") - .field("search_analyzer", "search") + .field("type", "string") + .field("index_analyzer", "index") + .field("search_analyzer", "search") .endObject() .endObject() .endObject().endObject(); @@ -1820,7 +1820,7 @@ public void testQueryStringWithSynonyms() throws IOException { assertHitCount(searchResponse, 1); searchResponse = client().prepareSearch().setQuery(QueryBuilders.queryString("fast").defaultField("text").defaultOperator(QueryStringQueryBuilder.Operator.AND)).get(); assertHitCount(searchResponse, 1); - + client().prepareIndex("test", "test", "2").setSource(jsonBuilder().startObject() .field("text", "fast brown fox") .endObject())