From 0ef2493b2c2ce7f5845736e1e5f501fd5ae1a182 Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Mon, 14 Oct 2013 12:58:55 +0200 Subject: [PATCH] Throw an exception if a type's mapping root node is not equal to the type in question. Also, fix all the problems it brought up in tests. Removed OverrideTypeMappingTests as it is no longer relevant. Better naming for the default percolator mapping and change it's content use _default_ as root node. Closes #4038 --- .../index/mapper/DocumentMapperParser.java | 20 +- .../index/mapper/MapperService.java | 16 +- .../SimpleRecoveryLocalGatewayTests.java | 14 +- .../org/elasticsearch/get/GetActionTests.java | 28 +-- .../OverrideTypeMappingTests.java | 50 ----- .../source/DefaultSourceMappingTests.java | 6 +- .../mapping/SimpleGetMappingsTests.java | 30 +-- .../percolator/TTLPercolatorTests.java | 37 ++-- .../child/SimpleChildQuerySearchTests.java | 74 ++++---- .../search/fields/SearchFieldsTests.java | 8 +- .../search/query/SimpleQueryTests.java | 174 +++++++++--------- 11 files changed, 214 insertions(+), 243 deletions(-) delete mode 100644 src/test/java/org/elasticsearch/index/mapper/overridetype/OverrideTypeMappingTests.java diff --git a/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java b/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java index 1cf7541cb12..da37b5de4e2 100644 --- a/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java +++ b/src/main/java/org/elasticsearch/index/mapper/DocumentMapperParser.java @@ -249,22 +249,26 @@ public class DocumentMapperParser extends AbstractIndexComponent { } int size = root.size(); switch (size) { - case 0: - // if we don't have any keys throw an exception - throw new MapperParsingException("malformed mapping no root object found"); - case 1: - break; - default: - // we always assume the first and single key is the mapping type root - throw new MapperParsingException("mapping must have the `type` as the root object"); + case 0: + // if we don't have any keys throw an exception + throw new MapperParsingException("malformed mapping no root object found"); + case 1: + break; + default: + // we always assume the first and single key is the mapping type root + throw new MapperParsingException("mapping must have the `type` as the root object"); } String rootName = root.keySet().iterator().next(); if (type == null) { type = rootName; + } else if (!type.equals(rootName)) { + // we always assume the first and single key is the mapping type root + throw new MapperParsingException("mapping must have the `type` as the root object. Got [" + rootName + "], expected [" + type + "]"); } + return new Tuple>(type, (Map) root.get(rootName)); } } diff --git a/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/src/main/java/org/elasticsearch/index/mapper/MapperService.java index 1b9c417723e..9db3a184af7 100644 --- a/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -81,7 +81,7 @@ public class MapperService extends AbstractIndexComponent implements Iterable mappers = ImmutableMap.of(); @@ -151,7 +151,7 @@ public class MapperService extends AbstractIndexComponent implements Iterable 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 class SimpleRecoveryLocalGatewayTests extends AbstractIntegrationTest { 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 class SimpleRecoveryLocalGatewayTests extends AbstractIntegrationTest { 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 ab3a7918c01..3a19853a9ae 100644 --- a/src/test/java/org/elasticsearch/get/GetActionTests.java +++ b/src/test/java/org/elasticsearch/get/GetActionTests.java @@ -228,8 +228,8 @@ public class GetActionTests extends AbstractIntegrationTest { 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() @@ -397,12 +397,12 @@ public class GetActionTests extends AbstractIntegrationTest { @Test public void testThatGetFromTranslogShouldWorkWithExclude() throws Exception { - String index = "test"; + String index = "test"; String type = "type1"; String mapping = jsonBuilder() .startObject() - .startObject("source_excludes") + .startObject(type) .startObject("_source") .array("excludes", "excluded") .endObject() @@ -432,12 +432,12 @@ public class GetActionTests extends AbstractIntegrationTest { @Test public void testThatGetFromTranslogShouldWorkWithInclude() throws Exception { - String index = "test"; + String index = "test"; String type = "type1"; String mapping = jsonBuilder() .startObject() - .startObject("source_excludes") + .startObject(type) .startObject("_source") .array("includes", "included") .endObject() @@ -468,12 +468,12 @@ public class GetActionTests extends AbstractIntegrationTest { @SuppressWarnings("unchecked") @Test public void testThatGetFromTranslogShouldWorkWithIncludeExcludeAndFields() throws Exception { - String index = "test"; + String index = "test"; String type = "type1"; String mapping = jsonBuilder() .startObject() - .startObject("source_excludes") + .startObject(type) .startObject("_source") .array("includes", "included") .array("exlcudes", "excluded") @@ -552,7 +552,8 @@ public class GetActionTests extends AbstractIntegrationTest { try { client().prepareGet("test", "type1", "1").setVersion(2).execute().actionGet(); assert false; - } catch (VersionConflictEngineException e) {} + } catch (VersionConflictEngineException e) { + } // From Lucene index: client().admin().indices().prepareRefresh("test").execute().actionGet(); @@ -571,7 +572,8 @@ public class GetActionTests extends AbstractIntegrationTest { try { client().prepareGet("test", "type1", "1").setVersion(2).setRealtime(false).execute().actionGet(); assert false; - } catch (VersionConflictEngineException e) {} + } catch (VersionConflictEngineException e) { + } logger.info("--> index doc 1 again, so increasing the version"); client().prepareIndex("test", "type1", "1").setSource("field1", "value1", "field2", "value2").execute().actionGet(); @@ -587,7 +589,8 @@ public class GetActionTests extends AbstractIntegrationTest { try { client().prepareGet("test", "type1", "1").setVersion(1).execute().actionGet(); assert false; - } catch (VersionConflictEngineException e) {} + } catch (VersionConflictEngineException e) { + } response = client().prepareGet("test", "type1", "1").setVersion(2).execute().actionGet(); assertThat(response.isExists(), equalTo(true)); @@ -606,7 +609,8 @@ public class GetActionTests extends AbstractIntegrationTest { try { client().prepareGet("test", "type1", "1").setVersion(1).setRealtime(false).execute().actionGet(); assert false; - } catch (VersionConflictEngineException e) {} + } catch (VersionConflictEngineException e) { + } response = client().prepareGet("test", "type1", "1").setVersion(2).setRealtime(false).execute().actionGet(); assertThat(response.isExists(), equalTo(true)); diff --git a/src/test/java/org/elasticsearch/index/mapper/overridetype/OverrideTypeMappingTests.java b/src/test/java/org/elasticsearch/index/mapper/overridetype/OverrideTypeMappingTests.java deleted file mode 100644 index d4d6e4c5f92..00000000000 --- a/src/test/java/org/elasticsearch/index/mapper/overridetype/OverrideTypeMappingTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to ElasticSearch and Shay Banon under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. ElasticSearch licenses this - * file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.mapper.overridetype; - -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.index.mapper.DocumentMapper; -import org.elasticsearch.index.mapper.MapperTestUtils; -import org.elasticsearch.test.ElasticsearchTestCase; -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; - -/** - * - */ -public class OverrideTypeMappingTests extends ElasticsearchTestCase { - - @Test - public void testOverrideType() throws Exception { - String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") - .startObject("_source").field("enabled", false).endObject() - .endObject().endObject().string(); - - DocumentMapper mapper = MapperTestUtils.newParser().parse("my_type", mapping); - assertThat(mapper.type(), equalTo("my_type")); - assertThat(mapper.sourceMapper().enabled(), equalTo(false)); - - mapper = MapperTestUtils.newParser().parse(mapping); - assertThat(mapper.type(), equalTo("type")); - assertThat(mapper.sourceMapper().enabled(), equalTo(false)); - } -} 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 3662b09ff19..adc3892e3d2 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 class DefaultSourceMappingTests extends ElasticsearchTestCase { // 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 class DefaultSourceMappingTests extends ElasticsearchTestCase { 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/indices/mapping/SimpleGetMappingsTests.java b/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsTests.java index e6d37e4e446..55ae1e089c5 100644 --- a/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsTests.java +++ b/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsTests.java @@ -26,6 +26,8 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.test.AbstractIntegrationTest; import org.junit.Test; +import java.io.IOException; + import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.hamcrest.Matchers.*; @@ -42,22 +44,27 @@ public class SimpleGetMappingsTests extends AbstractIntegrationTest { assertThat(response.mappings().get("index").size(), equalTo(0)); } + + private XContentBuilder getMappingForType(String type) throws IOException { + return jsonBuilder().startObject().startObject(type).startObject("properties") + .startObject("field1").field("type", "string").endObject() + .endObject().endObject().endObject(); + } + + @Test public void simpleGetMappings() throws Exception { - XContentBuilder mapping = jsonBuilder().startObject().startObject("properties") - .startObject("field1").field("type", "string").endObject() - .endObject().endObject(); client().admin().indices().prepareCreate("indexa") - .addMapping("typeA", mapping) - .addMapping("typeB", mapping) - .addMapping("Atype", mapping) - .addMapping("Btype", mapping) + .addMapping("typeA", getMappingForType("typeA")) + .addMapping("typeB", getMappingForType("typeB")) + .addMapping("Atype", getMappingForType("Atype")) + .addMapping("Btype", getMappingForType("Btype")) .execute().actionGet(); client().admin().indices().prepareCreate("indexb") - .addMapping("typeA", mapping) - .addMapping("typeB", mapping) - .addMapping("Atype", mapping) - .addMapping("Btype", mapping) + .addMapping("typeA", getMappingForType("typeA")) + .addMapping("typeB", getMappingForType("typeB")) + .addMapping("Atype", getMappingForType("Atype")) + .addMapping("Btype", getMappingForType("Btype")) .execute().actionGet(); ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); @@ -132,4 +139,5 @@ public class SimpleGetMappingsTests extends AbstractIntegrationTest { assertThat(response.mappings().get("indexb").get("Atype"), notNullValue()); assertThat(response.mappings().get("indexb").get("Btype"), notNullValue()); } + } diff --git a/src/test/java/org/elasticsearch/percolator/TTLPercolatorTests.java b/src/test/java/org/elasticsearch/percolator/TTLPercolatorTests.java index 1659495421a..eeae4d0fc21 100644 --- a/src/test/java/org/elasticsearch/percolator/TTLPercolatorTests.java +++ b/src/test/java/org/elasticsearch/percolator/TTLPercolatorTests.java @@ -19,7 +19,7 @@ import static org.hamcrest.Matchers.*; /** */ -@ClusterScope(scope=Scope.TEST) +@ClusterScope(scope = Scope.TEST) public class TTLPercolatorTests extends AbstractIntegrationTest { private static final long PURGE_INTERVAL = 200; @@ -38,15 +38,20 @@ public class TTLPercolatorTests extends AbstractIntegrationTest { client.admin().indices().prepareDelete().execute().actionGet(); ensureGreen(); - String mapping = XContentFactory.jsonBuilder().startObject().startObject("_percolator") + String precolatorMapping = XContentFactory.jsonBuilder().startObject().startObject("_percolator") + .startObject("_ttl").field("enabled", true).endObject() + .startObject("_timestamp").field("enabled", true).endObject() + .endObject().endObject().string(); + + String typeMapping = XContentFactory.jsonBuilder().startObject().startObject("type1") .startObject("_ttl").field("enabled", true).endObject() .startObject("_timestamp").field("enabled", true).endObject() .endObject().endObject().string(); client.admin().indices().prepareCreate("test") .setSettings(settingsBuilder().put("index.number_of_shards", 2)) - .addMapping("_percolator", mapping) - .addMapping("type1", mapping) + .addMapping("_percolator", precolatorMapping) + .addMapping("type1", typeMapping) .execute().actionGet(); ensureGreen(); @@ -70,12 +75,12 @@ public class TTLPercolatorTests extends AbstractIntegrationTest { PercolateResponse percolateResponse = client.preparePercolate() .setIndices("test").setDocumentType("type1") .setSource(jsonBuilder() - .startObject() - .startObject("doc") - .field("field1", "value1") - .endObject() - .endObject() - ).execute().actionGet(); + .startObject() + .startObject("doc") + .field("field1", "value1") + .endObject() + .endObject() + ).execute().actionGet(); assertNoFailures(percolateResponse); if (percolateResponse.getMatches().length == 0) { // OK, ttl + purgeInterval has passed (slow machine or many other tests were running at the same time @@ -111,12 +116,12 @@ public class TTLPercolatorTests extends AbstractIntegrationTest { percolateResponse = client.preparePercolate() .setIndices("test").setDocumentType("type1") .setSource(jsonBuilder() - .startObject() - .startObject("doc") - .field("field1", "value1") - .endObject() - .endObject() - ).execute().actionGet(); + .startObject() + .startObject("doc") + .field("field1", "value1") + .endObject() + .endObject() + ).execute().actionGet(); assertNoFailures(percolateResponse); assertThat(percolateResponse.getMatches(), emptyArray()); } diff --git a/src/test/java/org/elasticsearch/search/child/SimpleChildQuerySearchTests.java b/src/test/java/org/elasticsearch/search/child/SimpleChildQuerySearchTests.java index a4403e49472..7eaab39afc3 100644 --- a/src/test/java/org/elasticsearch/search/child/SimpleChildQuerySearchTests.java +++ b/src/test/java/org/elasticsearch/search/child/SimpleChildQuerySearchTests.java @@ -75,14 +75,14 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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(); @@ -145,7 +145,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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 @@ -171,7 +171,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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 @@ -291,7 +291,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { 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(); @@ -337,7 +337,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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 @@ -381,7 +381,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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(); @@ -441,7 +441,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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 @@ -549,7 +549,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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 @@ -657,7 +657,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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 @@ -704,7 +704,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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 @@ -774,7 +774,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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 @@ -814,7 +814,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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 @@ -845,7 +845,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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; @@ -890,7 +890,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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(); @@ -924,7 +924,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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"; @@ -964,7 +964,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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"; @@ -1008,11 +1008,11 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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(); @@ -1116,7 +1116,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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") @@ -1134,7 +1134,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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") @@ -1155,11 +1155,11 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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(); @@ -1296,7 +1296,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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(); @@ -1333,7 +1333,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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 @@ -1350,7 +1350,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { } 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) @@ -1401,7 +1401,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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 class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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 class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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 class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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 class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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 class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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 class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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 class SimpleChildQuerySearchTests extends AbstractIntegrationTest { ).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(); @@ -1883,13 +1883,13 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { assertThat(putMappingResponse.isAcknowledged(), equalTo(true)); GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("test").execute().actionGet(); - Map mapping = getMappingsResponse.getMappings().get("test").get("child").getSourceAsMap(); + Map mapping = getMappingsResponse.getMappings().get("test").get("child").getSourceAsMap(); assertThat(mapping.size(), equalTo(1)); assertThat(mapping.get("properties"), notNullValue()); 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(); @@ -1908,7 +1908,7 @@ public class SimpleChildQuerySearchTests extends AbstractIntegrationTest { .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 145c6d40fb5..9680f2be75f 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 @@ import static org.hamcrest.Matchers.*; * */ public class SearchFieldsTests extends AbstractIntegrationTest { - + @Override public Settings getSettings() { return randomSettingsBuilder() @@ -62,7 +62,7 @@ public class SearchFieldsTests extends AbstractIntegrationTest { 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 class SearchFieldsTests extends AbstractIntegrationTest { 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 class SearchFieldsTests extends AbstractIntegrationTest { 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 f0849c120dc..d474359394e 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 class SimpleQueryTests extends AbstractIntegrationTest { 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 class SimpleQueryTests extends AbstractIntegrationTest { 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 class SimpleQueryTests extends AbstractIntegrationTest { 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 class SimpleQueryTests extends AbstractIntegrationTest { } } } - + @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 class SimpleQueryTests extends AbstractIntegrationTest { .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 class SimpleQueryTests extends AbstractIntegrationTest { 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 class SimpleQueryTests extends AbstractIntegrationTest { 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 class SimpleQueryTests extends AbstractIntegrationTest { 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 class SimpleQueryTests extends AbstractIntegrationTest { @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 class SimpleQueryTests extends AbstractIntegrationTest { @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(); @@ -1201,7 +1201,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest { @Test public void testNumericTermsAndRanges() throws Exception { - client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)) + client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)) .addMapping("type1", jsonBuilder().startObject().startObject("type1").startObject("properties") .startObject("num_byte").field("type", "byte").endObject() .startObject("num_short").field("type", "short").endObject() @@ -1330,7 +1330,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest { @Test public void testNumericRangeFilter_2826() throws Exception { - client().admin().indices().prepareCreate("test").setSettings( + client().admin().indices().prepareCreate("test").setSettings( ImmutableSettings.settingsBuilder() .put("index.number_of_shards", 1) .put("index.number_of_replicas", 0) @@ -1407,7 +1407,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest { @Test // see #2926 public void testMustNot() throws ElasticSearchException, IOException { - client().admin().indices().prepareCreate("test").setSettings( + client().admin().indices().prepareCreate("test").setSettings( ImmutableSettings.settingsBuilder() .put("index.number_of_shards", 2) .put("index.number_of_replicas", 0) @@ -1581,41 +1581,41 @@ public class SimpleQueryTests extends AbstractIntegrationTest { .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(); @@ -1689,7 +1689,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest { 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 { @@ -1700,18 +1700,18 @@ public class SimpleQueryTests extends AbstractIntegrationTest { .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(); @@ -1728,7 +1728,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest { 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()) @@ -1739,7 +1739,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest { 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() @@ -1753,13 +1753,13 @@ public class SimpleQueryTests extends AbstractIntegrationTest { .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(); @@ -1772,7 +1772,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest { 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()) @@ -1781,7 +1781,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest { 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() @@ -1791,18 +1791,18 @@ public class SimpleQueryTests extends AbstractIntegrationTest { .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(); @@ -1819,7 +1819,7 @@ public class SimpleQueryTests extends AbstractIntegrationTest { 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())