Remove `index.mapping.single_type=false` from core/tests (#25331)
This change cleans up core tests to not use `index.mapping.single_type=false` but instead where applicable use a single type or markt the index as created with a pre 6.x version. Relates to #24961
This commit is contained in:
parent
343e7571b9
commit
29e80eea40
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.action.bulk;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.DocWriteResponse;
|
||||
import org.elasticsearch.action.admin.indices.alias.Alias;
|
||||
import org.elasticsearch.action.delete.DeleteRequest;
|
||||
|
@ -42,6 +43,7 @@ import org.elasticsearch.script.ScriptException;
|
|||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -53,6 +55,8 @@ import static org.elasticsearch.action.DocWriteRequest.OpType;
|
|||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
||||
|
@ -66,7 +70,7 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
|
|||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return Collections.singleton(CustomScriptPlugin.class);
|
||||
return Arrays.asList(InternalSettingsPlugin.class, CustomScriptPlugin.class);
|
||||
}
|
||||
|
||||
public static class CustomScriptPlugin extends MockScriptPlugin {
|
||||
|
@ -457,7 +461,7 @@ public class BulkWithUpdatesIT extends ESIntegTestCase {
|
|||
*/
|
||||
public void testBulkUpdateChildMissingParentRouting() throws Exception {
|
||||
assertAcked(prepareCreate("test")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.setSettings("index.version.created", Version.V_5_6_0.id) // allows for multiple types
|
||||
.addMapping("parent", "{\"parent\":{}}", XContentType.JSON)
|
||||
.addMapping("child", "{\"child\": {\"_parent\": {\"type\": \"parent\"}}}", XContentType.JSON));
|
||||
ensureGreen();
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.elasticsearch.cluster.metadata;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingClusterStateUpdateRequest;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.service.ClusterService;
|
||||
|
@ -27,8 +28,11 @@ import org.elasticsearch.common.xcontent.XContentType;
|
|||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
@ -36,6 +40,11 @@ import static org.hamcrest.Matchers.is;
|
|||
|
||||
public class MetaDataMappingServiceTests extends ESSingleNodeTestCase {
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> getPlugins() {
|
||||
return Collections.singleton(InternalSettingsPlugin.class);
|
||||
}
|
||||
|
||||
// Tests _parent meta field logic, because part of the validation is in MetaDataMappingService
|
||||
public void testAddChildTypePointingToAlreadyExistingType() throws Exception {
|
||||
createIndex("test", Settings.EMPTY, "type", "field", "type=keyword");
|
||||
|
@ -54,7 +63,7 @@ public class MetaDataMappingServiceTests extends ESSingleNodeTestCase {
|
|||
// Tests _parent meta field logic, because part of the validation is in MetaDataMappingService
|
||||
public void testAddExtraChildTypePointingToAlreadyParentExistingType() throws Exception {
|
||||
IndexService indexService = createIndex("test", client().admin().indices().prepareCreate("test")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.setSettings("index.version.created", Version.V_5_6_0.id)
|
||||
.addMapping("parent")
|
||||
.addMapping("child1", "_parent", "type=parent")
|
||||
);
|
||||
|
|
|
@ -318,7 +318,7 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
|
|||
// clean two nodes
|
||||
internalCluster().startNodes(2, Settings.builder().put("gateway.recover_after_nodes", 2).build());
|
||||
|
||||
assertAcked(client().admin().indices().prepareCreate("test").setSettings("index.mapping.single_type", false));
|
||||
assertAcked(client().admin().indices().prepareCreate("test"));
|
||||
client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject().field("field", "value1").endObject()).execute().actionGet();
|
||||
client().admin().indices().prepareFlush().execute().actionGet();
|
||||
client().prepareIndex("test", "type1", "2").setSource(jsonBuilder().startObject().field("field", "value2").endObject()).execute().actionGet();
|
||||
|
@ -350,10 +350,7 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
|
|||
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet(), 3);
|
||||
}
|
||||
|
||||
logger.info("--> add some metadata, additional type and template");
|
||||
client().admin().indices().preparePutMapping("test").setType("type2")
|
||||
.setSource(jsonBuilder().startObject().startObject("type2").endObject().endObject())
|
||||
.execute().actionGet();
|
||||
logger.info("--> add some metadata and additional template");
|
||||
client().admin().indices().preparePutTemplate("template_1")
|
||||
.setTemplate("te*")
|
||||
.setOrder(0)
|
||||
|
@ -381,7 +378,6 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState();
|
||||
assertThat(state.metaData().index("test").mapping("type2"), notNullValue());
|
||||
assertThat(state.metaData().templates().get("template_1").patterns(), equalTo(Collections.singletonList("te*")));
|
||||
assertThat(state.metaData().index("test").getAliases().get("test_alias"), notNullValue());
|
||||
assertThat(state.metaData().index("test").getAliases().get("test_alias").filter(), notNullValue());
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.get;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.DocWriteResponse;
|
||||
import org.elasticsearch.action.ShardOperationFailedException;
|
||||
import org.elasticsearch.action.admin.indices.alias.Alias;
|
||||
|
@ -38,9 +39,12 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.engine.VersionConflictEngineException;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
@ -58,6 +62,11 @@ import static org.hamcrest.Matchers.startsWith;
|
|||
|
||||
public class GetActionIT extends ESIntegTestCase {
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return Collections.singleton(InternalSettingsPlugin.class);
|
||||
}
|
||||
|
||||
public void testSimpleGet() {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", "field1", "type=keyword,store=true", "field2", "type=keyword,store=true")
|
||||
|
@ -246,15 +255,55 @@ public class GetActionIT extends ESIntegTestCase {
|
|||
.startObject("field").field("type", "text").field("store", true).endObject()
|
||||
.endObject()
|
||||
.endObject().endObject().string();
|
||||
String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type2")
|
||||
.startObject("properties")
|
||||
.startObject("field").field("type", "text").field("store", true).endObject()
|
||||
.endObject()
|
||||
.endObject().endObject().string();
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", mapping1, XContentType.JSON)
|
||||
.addMapping("type2", mapping2, XContentType.JSON)
|
||||
.setSettings("index.refresh_interval", -1, "index.mapping.single_type", false));
|
||||
.addMapping("type1", mapping1, XContentType.JSON));
|
||||
ensureGreen();
|
||||
|
||||
GetResponse response = client().prepareGet("test", "type1", "1").get();
|
||||
assertThat(response.isExists(), equalTo(false));
|
||||
assertThat(response.isExists(), equalTo(false));
|
||||
|
||||
client().prepareIndex("test", "type1", "1")
|
||||
.setSource(jsonBuilder().startObject().array("field", "1", "2").endObject()).get();
|
||||
|
||||
response = client().prepareGet("test", "type1", "1").setStoredFields("field").get();
|
||||
assertThat(response.isExists(), equalTo(true));
|
||||
assertThat(response.getId(), equalTo("1"));
|
||||
assertThat(response.getType(), equalTo("type1"));
|
||||
Set<String> fields = new HashSet<>(response.getFields().keySet());
|
||||
assertThat(fields, equalTo(singleton("field")));
|
||||
assertThat(response.getFields().get("field").getValues().size(), equalTo(2));
|
||||
assertThat(response.getFields().get("field").getValues().get(0).toString(), equalTo("1"));
|
||||
assertThat(response.getFields().get("field").getValues().get(1).toString(), equalTo("2"));
|
||||
|
||||
// Now test values being fetched from stored fields.
|
||||
refresh();
|
||||
response = client().prepareGet("test", "type1", "1").setStoredFields("field").get();
|
||||
assertThat(response.isExists(), equalTo(true));
|
||||
assertThat(response.getId(), equalTo("1"));
|
||||
fields = new HashSet<>(response.getFields().keySet());
|
||||
assertThat(fields, equalTo(singleton("field")));
|
||||
assertThat(response.getFields().get("field").getValues().size(), equalTo(2));
|
||||
assertThat(response.getFields().get("field").getValues().get(0).toString(), equalTo("1"));
|
||||
assertThat(response.getFields().get("field").getValues().get(1).toString(), equalTo("2"));
|
||||
}
|
||||
|
||||
public void testGetDocWithMultivaluedFieldsMultiTypeBWC() throws Exception {
|
||||
assertTrue("remove this multi type test", Version.CURRENT.before(Version.fromString("7.0.0")));
|
||||
String mapping1 = XContentFactory.jsonBuilder().startObject().startObject("type1")
|
||||
.startObject("properties")
|
||||
.startObject("field").field("type", "text").field("store", true).endObject()
|
||||
.endObject()
|
||||
.endObject().endObject().string();
|
||||
String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type2")
|
||||
.startObject("properties")
|
||||
.startObject("field").field("type", "text").field("store", true).endObject()
|
||||
.endObject()
|
||||
.endObject().endObject().string();
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", mapping1, XContentType.JSON)
|
||||
.addMapping("type2", mapping2, XContentType.JSON)
|
||||
.setSettings("index.refresh_interval", -1, "index.version.created", Version.V_5_6_0.id)); // multi types in 5.6
|
||||
ensureGreen();
|
||||
|
||||
GetResponse response = client().prepareGet("test", "type1", "1").get();
|
||||
|
@ -263,10 +312,10 @@ public class GetActionIT extends ESIntegTestCase {
|
|||
assertThat(response.isExists(), equalTo(false));
|
||||
|
||||
client().prepareIndex("test", "type1", "1")
|
||||
.setSource(jsonBuilder().startObject().array("field", "1", "2").endObject()).get();
|
||||
.setSource(jsonBuilder().startObject().array("field", "1", "2").endObject()).get();
|
||||
|
||||
client().prepareIndex("test", "type2", "1")
|
||||
.setSource(jsonBuilder().startObject().array("field", "1", "2").endObject()).get();
|
||||
.setSource(jsonBuilder().startObject().array("field", "1", "2").endObject()).get();
|
||||
|
||||
response = client().prepareGet("test", "type1", "1").setStoredFields("field").get();
|
||||
assertThat(response.isExists(), equalTo(true));
|
||||
|
@ -524,12 +573,47 @@ public class GetActionIT extends ESIntegTestCase {
|
|||
assertThat(response.getResponses()[2].getResponse().getSourceAsMap().get("field").toString(), equalTo("value2"));
|
||||
}
|
||||
|
||||
public void testGetFieldsMetaData() throws Exception {
|
||||
public void testGetFieldsMetaDataWithRouting() throws Exception {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("doc", "field1", "type=keyword,store=true")
|
||||
.addAlias(new Alias("alias"))
|
||||
.setSettings("index.refresh_interval", -1, "index.version.created", Version.V_5_6_0.id)); // multi types in 5.6
|
||||
|
||||
client().prepareIndex("test", "doc", "1")
|
||||
.setRouting("1")
|
||||
.setSource(jsonBuilder().startObject().field("field1", "value").endObject())
|
||||
.get();
|
||||
|
||||
GetResponse getResponse = client().prepareGet(indexOrAlias(), "doc", "1")
|
||||
.setRouting("1")
|
||||
.setStoredFields("field1")
|
||||
.get();
|
||||
assertThat(getResponse.isExists(), equalTo(true));
|
||||
assertThat(getResponse.getField("field1").isMetadataField(), equalTo(false));
|
||||
assertThat(getResponse.getField("field1").getValue().toString(), equalTo("value"));
|
||||
assertThat(getResponse.getField("_routing").isMetadataField(), equalTo(true));
|
||||
assertThat(getResponse.getField("_routing").getValue().toString(), equalTo("1"));
|
||||
|
||||
flush();
|
||||
|
||||
getResponse = client().prepareGet(indexOrAlias(), "doc", "1")
|
||||
.setStoredFields("field1")
|
||||
.setRouting("1")
|
||||
.get();
|
||||
assertThat(getResponse.isExists(), equalTo(true));
|
||||
assertThat(getResponse.getField("field1").isMetadataField(), equalTo(false));
|
||||
assertThat(getResponse.getField("field1").getValue().toString(), equalTo("value"));
|
||||
assertThat(getResponse.getField("_routing").isMetadataField(), equalTo(true));
|
||||
assertThat(getResponse.getField("_routing").getValue().toString(), equalTo("1"));
|
||||
}
|
||||
|
||||
public void testGetFieldsMetaDataWithParentChild() throws Exception {
|
||||
assertTrue("remove this multi type test", Version.CURRENT.before(Version.fromString("7.0.0")));
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("parent")
|
||||
.addMapping("my-type1", "_parent", "type=parent", "field1", "type=keyword,store=true")
|
||||
.addAlias(new Alias("alias"))
|
||||
.setSettings("index.refresh_interval", -1, "index.mapping.single_type", false));
|
||||
.setSettings("index.refresh_interval", -1, "index.version.created", Version.V_5_6_0.id)); // multi types in 5.6
|
||||
|
||||
client().prepareIndex("test", "my-type1", "1")
|
||||
.setRouting("1")
|
||||
|
@ -593,7 +677,7 @@ public class GetActionIT extends ESIntegTestCase {
|
|||
|
||||
public void testGetFieldsComplexField() throws Exception {
|
||||
assertAcked(prepareCreate("my-index")
|
||||
.setSettings("index.refresh_interval", -1, "index.mapping.single_type", false)
|
||||
.setSettings("index.refresh_interval", -1, "index.version.created", Version.V_5_6_0.id) // multi types in 5.6
|
||||
.addMapping("my-type2", jsonBuilder().startObject().startObject("my-type2").startObject("properties")
|
||||
.startObject("field1").field("type", "object").startObject("properties")
|
||||
.startObject("field2").field("type", "object").startObject("properties")
|
||||
|
|
|
@ -151,11 +151,10 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
|
||||
public void testNestedHaveIdAndTypeFields() throws Exception {
|
||||
DocumentMapperParser mapperParser1 = createIndex("index1", Settings.builder()
|
||||
.put("index.mapping.single_type", false).build()
|
||||
).mapperService().documentMapperParser();
|
||||
DocumentMapperParser mapperParser2 = createIndex("index2", Settings.builder()
|
||||
.put("index.mapping.single_type", true).build()
|
||||
.put("index.version.created", Version.V_5_6_0) // allows for multiple types
|
||||
.build()
|
||||
).mapperService().documentMapperParser();
|
||||
DocumentMapperParser mapperParser2 = createIndex("index2").mapperService().documentMapperParser();
|
||||
|
||||
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties");
|
||||
{
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.elasticsearch.index.mapper;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.DocWriteResponse;
|
||||
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
|
||||
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
|
||||
|
@ -28,9 +29,12 @@ import org.elasticsearch.cluster.metadata.MappingMetaData;
|
|||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.indices.TypeMissingException;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
@ -42,6 +46,11 @@ import static org.hamcrest.Matchers.instanceOf;
|
|||
|
||||
public class DynamicMappingIT extends ESIntegTestCase {
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return Collections.singleton(InternalSettingsPlugin.class);
|
||||
}
|
||||
|
||||
public void testConflictingDynamicMappings() {
|
||||
// we don't use indexRandom because the order of requests is important here
|
||||
createIndex("index");
|
||||
|
@ -75,7 +84,21 @@ public class DynamicMappingIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
public void testMappingsPropagatedToMasterNodeImmediately() throws IOException {
|
||||
assertAcked(prepareCreate("index").setSettings("index.mapping.single_type", false));
|
||||
assertAcked(prepareCreate("index"));
|
||||
|
||||
// works when the type has been dynamically created
|
||||
client().prepareIndex("index", "type", "1").setSource("foo", 3).get();
|
||||
GetMappingsResponse mappings = client().admin().indices().prepareGetMappings("index").setTypes("type").get();
|
||||
assertMappingsHaveField(mappings, "index", "type", "foo");
|
||||
|
||||
// works if the type already existed
|
||||
client().prepareIndex("index", "type", "1").setSource("bar", "baz").get();
|
||||
mappings = client().admin().indices().prepareGetMappings("index").setTypes("type").get();
|
||||
assertMappingsHaveField(mappings, "index", "type", "bar");
|
||||
}
|
||||
|
||||
public void testMappingsPropagatedToMasterNodeImmediatelyMultiType() throws IOException {
|
||||
assertAcked(prepareCreate("index").setSettings("index.version.created", Version.V_5_6_0.id)); // allows for multiple types
|
||||
|
||||
// works when the type has been dynamically created
|
||||
client().prepareIndex("index", "type", "1").setSource("foo", 3).get();
|
||||
|
|
|
@ -22,20 +22,29 @@ package org.elasticsearch.index.mapper;
|
|||
import org.apache.lucene.index.DocValuesType;
|
||||
import org.apache.lucene.index.IndexOptions;
|
||||
import org.apache.lucene.index.IndexableField;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.mapper.MapperService.MergeReason;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class IdFieldMapperTests extends ESSingleNodeTestCase {
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> getPlugins() {
|
||||
return Collections.singleton(InternalSettingsPlugin.class);
|
||||
}
|
||||
|
||||
public void testIncludeInObjectNotAllowed() throws Exception {
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string();
|
||||
DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
|
||||
|
@ -51,7 +60,7 @@ public class IdFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
public void testDefaultsMultipleTypes() throws IOException {
|
||||
Settings indexSettings = Settings.builder()
|
||||
.put("index.mapping.single_type", false)
|
||||
.put("index.version.created", Version.V_5_6_0)
|
||||
.build();
|
||||
MapperService mapperService = createIndex("test", indexSettings).mapperService();
|
||||
DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false);
|
||||
|
@ -60,9 +69,7 @@ public class IdFieldMapperTests extends ESSingleNodeTestCase {
|
|||
}
|
||||
|
||||
public void testDefaultsSingleType() throws IOException {
|
||||
Settings indexSettings = Settings.builder()
|
||||
.put("index.mapping.single_type", true)
|
||||
.build();
|
||||
Settings indexSettings = Settings.EMPTY;
|
||||
MapperService mapperService = createIndex("test", indexSettings).mapperService();
|
||||
DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false);
|
||||
ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON));
|
||||
|
|
|
@ -49,11 +49,10 @@ public class IdFieldTypeTests extends FieldTypeTestCase {
|
|||
public void testTermsQueryWhenTypesAreEnabled() throws Exception {
|
||||
QueryShardContext context = Mockito.mock(QueryShardContext.class);
|
||||
Settings indexSettings = Settings.builder()
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_5_6_0) // allows for multiple types
|
||||
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
|
||||
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
|
||||
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
|
||||
.put("index.mapping.single_type", false).build();
|
||||
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).build();
|
||||
IndexMetaData indexMetaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(indexSettings).build();
|
||||
IndexSettings mockSettings = new IndexSettings(indexMetaData, Settings.EMPTY);
|
||||
Mockito.when(context.getIndexSettings()).thenReturn(mockSettings);
|
||||
|
@ -80,8 +79,7 @@ public class IdFieldTypeTests extends FieldTypeTestCase {
|
|||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
|
||||
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
|
||||
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
|
||||
.put("index.mapping.single_type", true).build();
|
||||
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).build();
|
||||
IndexMetaData indexMetaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(indexSettings).build();
|
||||
IndexSettings mockSettings = new IndexSettings(indexMetaData, Settings.EMPTY);
|
||||
Mockito.when(context.getIndexSettings()).thenReturn(mockSettings);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.index.mapper;
|
||||
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
|
@ -28,12 +29,15 @@ import org.elasticsearch.index.IndexService;
|
|||
import org.elasticsearch.index.mapper.KeywordFieldMapper.KeywordFieldType;
|
||||
import org.elasticsearch.index.mapper.MapperService.MergeReason;
|
||||
import org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -48,6 +52,11 @@ import static org.hamcrest.Matchers.startsWith;
|
|||
|
||||
public class MapperServiceTests extends ESSingleNodeTestCase {
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> getPlugins() {
|
||||
return Collections.singleton(InternalSettingsPlugin.class);
|
||||
}
|
||||
|
||||
public void testTypeNameStartsWithIllegalDot() {
|
||||
String index = "test-index";
|
||||
String type = ".test-type";
|
||||
|
@ -74,7 +83,8 @@ public class MapperServiceTests extends ESSingleNodeTestCase {
|
|||
}
|
||||
|
||||
public void testTypes() throws Exception {
|
||||
IndexService indexService1 = createIndex("index1", Settings.builder().put("index.mapping.single_type", false).build());
|
||||
IndexService indexService1 = createIndex("index1", Settings.builder().put("index.version.created", Version.V_5_6_0) // multi types
|
||||
.build());
|
||||
MapperService mapperService = indexService1.mapperService();
|
||||
assertEquals(Collections.emptySet(), mapperService.types());
|
||||
|
||||
|
@ -207,7 +217,8 @@ public class MapperServiceTests extends ESSingleNodeTestCase {
|
|||
}
|
||||
|
||||
public void testOtherDocumentMappersOnlyUpdatedWhenChangingFieldType() throws IOException {
|
||||
IndexService indexService = createIndex("test", Settings.builder().put("index.mapping.single_type", false).build());
|
||||
IndexService indexService = createIndex("test",
|
||||
Settings.builder().put("index.version.created", Version.V_5_6_0).build()); // multiple types
|
||||
|
||||
CompressedXContent simpleMapping = new CompressedXContent(XContentFactory.jsonBuilder().startObject()
|
||||
.startObject("properties")
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.lucene.index.IndexableField;
|
|||
import org.apache.lucene.index.SortedSetDocValues;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -89,7 +90,7 @@ public class TypeFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
public void testDefaultsMultipleTypes() throws IOException {
|
||||
Settings indexSettings = Settings.builder()
|
||||
.put("index.mapping.single_type", false)
|
||||
.put("index.version.created", Version.V_5_6_0)
|
||||
.build();
|
||||
MapperService mapperService = createIndex("test", indexSettings).mapperService();
|
||||
DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false);
|
||||
|
@ -100,9 +101,7 @@ public class TypeFieldMapperTests extends ESSingleNodeTestCase {
|
|||
}
|
||||
|
||||
public void testDefaultsSingleType() throws IOException {
|
||||
Settings indexSettings = Settings.builder()
|
||||
.put("index.mapping.single_type", true)
|
||||
.build();
|
||||
Settings indexSettings = Settings.EMPTY;
|
||||
MapperService mapperService = createIndex("test", indexSettings).mapperService();
|
||||
DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false);
|
||||
ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON));
|
||||
|
|
|
@ -62,8 +62,7 @@ public class TypeFieldTypeTests extends FieldTypeTestCase {
|
|||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
|
||||
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
|
||||
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
|
||||
.put("index.mapping.single_type", true).build();
|
||||
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).build();
|
||||
IndexMetaData indexMetaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(indexSettings).build();
|
||||
IndexSettings mockSettings = new IndexSettings(indexMetaData, Settings.EMPTY);
|
||||
Mockito.when(context.getIndexSettings()).thenReturn(mockSettings);
|
||||
|
@ -100,11 +99,11 @@ public class TypeFieldTypeTests extends FieldTypeTestCase {
|
|||
|
||||
QueryShardContext context = Mockito.mock(QueryShardContext.class);
|
||||
Settings indexSettings = Settings.builder()
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_5_6_0) // to allow for multiple types
|
||||
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
|
||||
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
|
||||
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
|
||||
.put("index.mapping.single_type", false).build();
|
||||
.build();
|
||||
IndexMetaData indexMetaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(indexSettings).build();
|
||||
IndexSettings mockSettings = new IndexSettings(indexMetaData, Settings.EMPTY);
|
||||
Mockito.when(context.getIndexSettings()).thenReturn(mockSettings);
|
||||
|
|
|
@ -21,22 +21,31 @@ package org.elasticsearch.index.mapper;
|
|||
|
||||
import org.apache.lucene.index.IndexOptions;
|
||||
import org.apache.lucene.index.IndexableField;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.mapper.MapperService.MergeReason;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class UidFieldMapperTests extends ESSingleNodeTestCase {
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> getPlugins() {
|
||||
return Collections.singleton(InternalSettingsPlugin.class);
|
||||
}
|
||||
|
||||
public void testDefaultsMultipleTypes() throws IOException {
|
||||
Settings indexSettings = Settings.builder()
|
||||
.put("index.mapping.single_type", false)
|
||||
.put("index.version.created", Version.V_5_6_0)
|
||||
.build();
|
||||
MapperService mapperService = createIndex("test", indexSettings).mapperService();
|
||||
DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false);
|
||||
|
@ -49,9 +58,7 @@ public class UidFieldMapperTests extends ESSingleNodeTestCase {
|
|||
}
|
||||
|
||||
public void testDefaultsSingleType() throws IOException {
|
||||
Settings indexSettings = Settings.builder()
|
||||
.put("index.mapping.single_type", true)
|
||||
.build();
|
||||
Settings indexSettings = Settings.EMPTY;
|
||||
MapperService mapperService = createIndex("test", indexSettings).mapperService();
|
||||
DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false);
|
||||
ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON));
|
||||
|
|
|
@ -52,11 +52,11 @@ public class UidFieldTypeTests extends FieldTypeTestCase {
|
|||
public void testTermsQueryWhenTypesAreEnabled() throws Exception {
|
||||
QueryShardContext context = Mockito.mock(QueryShardContext.class);
|
||||
Settings indexSettings = Settings.builder()
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_5_6_0) // to allow for multipel types
|
||||
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
|
||||
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
|
||||
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
|
||||
.put("index.mapping.single_type", false).build();
|
||||
.build();
|
||||
IndexMetaData indexMetaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(indexSettings).build();
|
||||
IndexSettings mockSettings = new IndexSettings(indexMetaData, Settings.EMPTY);
|
||||
Mockito.when(context.getIndexSettings()).thenReturn(mockSettings);
|
||||
|
@ -78,8 +78,7 @@ public class UidFieldTypeTests extends FieldTypeTestCase {
|
|||
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
||||
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
|
||||
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
|
||||
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())
|
||||
.put("index.mapping.single_type", true).build();
|
||||
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).build();
|
||||
IndexMetaData indexMetaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(indexSettings).build();
|
||||
IndexSettings mockSettings = new IndexSettings(indexMetaData, Settings.EMPTY);
|
||||
Mockito.when(context.getIndexSettings()).thenReturn(mockSettings);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.elasticsearch.indices;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionRequestBuilder;
|
||||
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse;
|
||||
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequestBuilder;
|
||||
|
@ -48,6 +49,7 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.index.IndexNotFoundException;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
@ -68,7 +70,7 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return Arrays.asList(TestPlugin.class);
|
||||
return Arrays.asList(TestPlugin.class, InternalSettingsPlugin.class);
|
||||
}
|
||||
|
||||
public void testSpecifiedIndexUnavailableMultipleIndices() throws Exception {
|
||||
|
@ -564,7 +566,40 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
verify(client().admin().indices().preparePutMapping("_all").setType("type1").setSource("field", "type=text"), true);
|
||||
|
||||
for (String index : Arrays.asList("foo", "foobar", "bar", "barbaz")) {
|
||||
assertAcked(prepareCreate(index).setSettings("index.mapping.single_type", false));
|
||||
assertAcked(prepareCreate(index));
|
||||
}
|
||||
|
||||
verify(client().admin().indices().preparePutMapping("foo").setType("type").setSource("field", "type=text"), false);
|
||||
assertThat(client().admin().indices().prepareGetMappings("foo").get().mappings().get("foo").get("type"), notNullValue());
|
||||
verify(client().admin().indices().preparePutMapping("b*").setType("type").setSource("field", "type=text"), false);
|
||||
assertThat(client().admin().indices().prepareGetMappings("bar").get().mappings().get("bar").get("type"), notNullValue());
|
||||
assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz").get("type"), notNullValue());
|
||||
verify(client().admin().indices().preparePutMapping("_all").setType("type").setSource("field", "type=text"), false);
|
||||
assertThat(client().admin().indices().prepareGetMappings("foo").get().mappings().get("foo").get("type"), notNullValue());
|
||||
assertThat(client().admin().indices().prepareGetMappings("foobar").get().mappings().get("foobar").get("type"), notNullValue());
|
||||
assertThat(client().admin().indices().prepareGetMappings("bar").get().mappings().get("bar").get("type"), notNullValue());
|
||||
assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz").get("type"), notNullValue());
|
||||
verify(client().admin().indices().preparePutMapping().setType("type").setSource("field", "type=text"), false);
|
||||
assertThat(client().admin().indices().prepareGetMappings("foo").get().mappings().get("foo").get("type"), notNullValue());
|
||||
assertThat(client().admin().indices().prepareGetMappings("foobar").get().mappings().get("foobar").get("type"), notNullValue());
|
||||
assertThat(client().admin().indices().prepareGetMappings("bar").get().mappings().get("bar").get("type"), notNullValue());
|
||||
assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz").get("type"), notNullValue());
|
||||
|
||||
|
||||
verify(client().admin().indices().preparePutMapping("c*").setType("type").setSource("field", "type=text"), true);
|
||||
|
||||
assertAcked(client().admin().indices().prepareClose("barbaz").get());
|
||||
verify(client().admin().indices().preparePutMapping("barbaz").setType("type").setSource("field", "type=text"), false);
|
||||
assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz").get("type"), notNullValue());
|
||||
}
|
||||
|
||||
public void testPutMappingMultiType() throws Exception {
|
||||
assertTrue("remove this multi type test", Version.CURRENT.before(Version.fromString("7.0.0")));
|
||||
verify(client().admin().indices().preparePutMapping("foo").setType("type1").setSource("field", "type=text"), true);
|
||||
verify(client().admin().indices().preparePutMapping("_all").setType("type1").setSource("field", "type=text"), true);
|
||||
|
||||
for (String index : Arrays.asList("foo", "foobar", "bar", "barbaz")) {
|
||||
assertAcked(prepareCreate(index).setSettings("index.version.created", Version.V_5_6_0.id)); // allows for multiple types
|
||||
}
|
||||
|
||||
verify(client().admin().indices().preparePutMapping("foo").setType("type1").setSource("field", "type=text"), false);
|
||||
|
|
|
@ -18,15 +18,20 @@
|
|||
*/
|
||||
package org.elasticsearch.indices.exists.types;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
|
||||
import org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.index.IndexNotFoundException;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_BLOCKS_READ;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_BLOCKS_WRITE;
|
||||
|
@ -37,10 +42,16 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertBloc
|
|||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class TypesExistsIT extends ESIntegTestCase {
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return Collections.singleton(InternalSettingsPlugin.class);
|
||||
}
|
||||
|
||||
public void testSimple() throws Exception {
|
||||
Client client = client();
|
||||
CreateIndexResponse response1 = client.admin().indices().prepareCreate("test1")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.setSettings("index.version.created", Version.V_5_6_0.id)
|
||||
.addMapping("type1", jsonBuilder().startObject().startObject("type1").endObject().endObject())
|
||||
.addMapping("type2", jsonBuilder().startObject().startObject("type2").endObject().endObject())
|
||||
.execute().actionGet();
|
||||
|
|
|
@ -19,16 +19,21 @@
|
|||
|
||||
package org.elasticsearch.indices.mapping;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -48,6 +53,11 @@ import static org.hamcrest.Matchers.nullValue;
|
|||
|
||||
public class SimpleGetFieldMappingsIT extends ESIntegTestCase {
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return Collections.singleton(InternalSettingsPlugin.class);
|
||||
}
|
||||
|
||||
public void testGetMappingsWhereThereAreNone() {
|
||||
createIndex("index");
|
||||
GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings().get();
|
||||
|
@ -64,14 +74,65 @@ public class SimpleGetFieldMappingsIT extends ESIntegTestCase {
|
|||
.endObject().endObject().endObject();
|
||||
}
|
||||
|
||||
public void testSimpleGetFieldMappings() throws Exception {
|
||||
public void testGetFieldMappings() throws Exception {
|
||||
|
||||
assertAcked(prepareCreate("indexa")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.addMapping("typeA", getMappingForType("typeA")));
|
||||
assertAcked(client().admin().indices().prepareCreate("indexb")
|
||||
.addMapping("typeB", getMappingForType("typeB")));
|
||||
|
||||
|
||||
// Get mappings by full name
|
||||
GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings("indexa").setTypes("typeA").setFields("field1", "obj.subfield").get();
|
||||
assertThat(response.fieldMappings("indexa", "typeA", "field1").fullName(), equalTo("field1"));
|
||||
assertThat(response.fieldMappings("indexa", "typeA", "field1").sourceAsMap(), hasKey("field1"));
|
||||
assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").fullName(), equalTo("obj.subfield"));
|
||||
assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").sourceAsMap(), hasKey("subfield"));
|
||||
assertThat(response.fieldMappings("indexb", "typeB", "field1"), nullValue());
|
||||
|
||||
// Get mappings by name
|
||||
response = client().admin().indices().prepareGetFieldMappings("indexa").setTypes("typeA").setFields("field1", "obj.subfield").get();
|
||||
assertThat(response.fieldMappings("indexa", "typeA", "field1").fullName(), equalTo("field1"));
|
||||
assertThat(response.fieldMappings("indexa", "typeA", "field1").sourceAsMap(), hasKey("field1"));
|
||||
assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").fullName(), equalTo("obj.subfield"));
|
||||
assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").sourceAsMap(), hasKey("subfield"));
|
||||
assertThat(response.fieldMappings("indexa", "typeB", "field1"), nullValue());
|
||||
assertThat(response.fieldMappings("indexb", "typeB", "field1"), nullValue());
|
||||
|
||||
// get mappings by name across multiple indices
|
||||
response = client().admin().indices().prepareGetFieldMappings().setTypes("typeA").setFields("obj.subfield").get();
|
||||
assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").fullName(), equalTo("obj.subfield"));
|
||||
assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").sourceAsMap(), hasKey("subfield"));
|
||||
assertThat(response.fieldMappings("indexa", "typeB", "obj.subfield"), nullValue());
|
||||
assertThat(response.fieldMappings("indexb", "typeB", "obj.subfield"), nullValue());
|
||||
|
||||
// get mappings by name across multiple types
|
||||
response = client().admin().indices().prepareGetFieldMappings("indexa").setFields("obj.subfield").get();
|
||||
assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").fullName(), equalTo("obj.subfield"));
|
||||
assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").sourceAsMap(), hasKey("subfield"));
|
||||
assertThat(response.fieldMappings("indexa", "typeA", "field1"), nullValue());
|
||||
assertThat(response.fieldMappings("indexb", "typeB", "obj.subfield"), nullValue());
|
||||
assertThat(response.fieldMappings("indexb", "typeB", "field1"), nullValue());
|
||||
|
||||
// get mappings by name across multiple types & indices
|
||||
response = client().admin().indices().prepareGetFieldMappings().setFields("obj.subfield").get();
|
||||
assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").fullName(), equalTo("obj.subfield"));
|
||||
assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").sourceAsMap(), hasKey("subfield"));
|
||||
assertThat(response.fieldMappings("indexa", "typeA", "field1"), nullValue());
|
||||
assertThat(response.fieldMappings("indexb", "typeB", "field1"), nullValue());
|
||||
assertThat(response.fieldMappings("indexb", "typeB", "obj.subfield").fullName(), equalTo("obj.subfield"));
|
||||
assertThat(response.fieldMappings("indexb", "typeB", "obj.subfield").sourceAsMap(), hasKey("subfield"));
|
||||
assertThat(response.fieldMappings("indexb", "typeB", "field1"), nullValue());
|
||||
}
|
||||
|
||||
public void testGetFieldMappingsMultiType() throws Exception {
|
||||
assertTrue("remove this multi type test", Version.CURRENT.before(Version.fromString("7.0.0")));
|
||||
assertAcked(prepareCreate("indexa")
|
||||
.setSettings("index.version.created", Version.V_5_6_0.id)
|
||||
.addMapping("typeA", getMappingForType("typeA"))
|
||||
.addMapping("typeB", getMappingForType("typeB")));
|
||||
assertAcked(client().admin().indices().prepareCreate("indexb")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.setSettings("index.version.created", Version.V_5_6_0.id)
|
||||
.addMapping("typeA", getMappingForType("typeA"))
|
||||
.addMapping("typeB", getMappingForType("typeB")));
|
||||
|
||||
|
@ -186,15 +247,14 @@ public class SimpleGetFieldMappingsIT extends ESIntegTestCase {
|
|||
|
||||
public void testGetFieldMappingsWithBlocks() throws Exception {
|
||||
assertAcked(prepareCreate("test")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.addMapping("typeA", getMappingForType("typeA"))
|
||||
.addMapping("typeB", getMappingForType("typeB")));
|
||||
.addMapping("doc", getMappingForType("doc")));
|
||||
|
||||
for (String block : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY)) {
|
||||
try {
|
||||
enableIndexBlock("test", block);
|
||||
GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings("test").setTypes("typeA").setFields("field1", "obj.subfield").get();
|
||||
assertThat(response.fieldMappings("test", "typeA", "field1").fullName(), equalTo("field1"));
|
||||
GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings("test").setTypes("doc")
|
||||
.setFields("field1", "obj.subfield").get();
|
||||
assertThat(response.fieldMappings("test", "doc", "field1").fullName(), equalTo("field1"));
|
||||
} finally {
|
||||
disableIndexBlock("test", block);
|
||||
}
|
||||
|
|
|
@ -19,15 +19,20 @@
|
|||
|
||||
package org.elasticsearch.indices.mapping;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
||||
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
|
||||
import org.elasticsearch.common.Priority;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.INDEX_METADATA_BLOCK;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_BLOCKS_METADATA;
|
||||
|
@ -41,6 +46,12 @@ import static org.hamcrest.Matchers.notNullValue;
|
|||
|
||||
@ClusterScope(randomDynamicTemplates = false)
|
||||
public class SimpleGetMappingsIT extends ESIntegTestCase {
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return Collections.singleton(InternalSettingsPlugin.class);
|
||||
}
|
||||
|
||||
public void testGetMappingsWhereThereAreNone() {
|
||||
createIndex("index");
|
||||
GetMappingsResponse response = client().admin().indices().prepareGetMappings().execute().actionGet();
|
||||
|
@ -56,14 +67,14 @@ public class SimpleGetMappingsIT extends ESIntegTestCase {
|
|||
|
||||
public void testSimpleGetMappings() throws Exception {
|
||||
client().admin().indices().prepareCreate("indexa")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.setSettings("index.version.created", Version.V_5_6_0.id)
|
||||
.addMapping("typeA", getMappingForType("typeA"))
|
||||
.addMapping("typeB", getMappingForType("typeB"))
|
||||
.addMapping("Atype", getMappingForType("Atype"))
|
||||
.addMapping("Btype", getMappingForType("Btype"))
|
||||
.execute().actionGet();
|
||||
client().admin().indices().prepareCreate("indexb")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.setSettings("index.version.created", Version.V_5_6_0.id)
|
||||
.addMapping("typeA", getMappingForType("typeA"))
|
||||
.addMapping("typeB", getMappingForType("typeB"))
|
||||
.addMapping("Atype", getMappingForType("Atype"))
|
||||
|
@ -145,9 +156,7 @@ public class SimpleGetMappingsIT extends ESIntegTestCase {
|
|||
|
||||
public void testGetMappingsWithBlocks() throws IOException {
|
||||
client().admin().indices().prepareCreate("test")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.addMapping("typeA", getMappingForType("typeA"))
|
||||
.addMapping("typeB", getMappingForType("typeB"))
|
||||
.addMapping("doc", getMappingForType("doc"))
|
||||
.execute().actionGet();
|
||||
ensureGreen();
|
||||
|
||||
|
@ -156,7 +165,7 @@ public class SimpleGetMappingsIT extends ESIntegTestCase {
|
|||
enableIndexBlock("test", block);
|
||||
GetMappingsResponse response = client().admin().indices().prepareGetMappings().execute().actionGet();
|
||||
assertThat(response.mappings().size(), equalTo(1));
|
||||
assertThat(response.mappings().get("test").size(), equalTo(2));
|
||||
assertThat(response.mappings().get("test").size(), equalTo(1));
|
||||
} finally {
|
||||
disableIndexBlock("test", block);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.indices.mapping;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
|
||||
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
|
||||
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
|
||||
|
@ -33,13 +34,17 @@ import org.elasticsearch.common.xcontent.XContentType;
|
|||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
|
@ -62,6 +67,11 @@ import static org.hamcrest.Matchers.not;
|
|||
@ClusterScope(randomDynamicTemplates = false)
|
||||
public class UpdateMappingIntegrationIT extends ESIntegTestCase {
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return Collections.singleton(InternalSettingsPlugin.class);
|
||||
}
|
||||
|
||||
public void testDynamicUpdates() throws Exception {
|
||||
client().admin().indices().prepareCreate("test")
|
||||
.setSettings(
|
||||
|
@ -69,7 +79,7 @@ public class UpdateMappingIntegrationIT extends ESIntegTestCase {
|
|||
.put("index.number_of_shards", 1)
|
||||
.put("index.number_of_replicas", 0)
|
||||
.put(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey(), Long.MAX_VALUE)
|
||||
.put("index.mapping.single_type", false)
|
||||
.put("index.version.created", Version.V_5_6_0) // for multiple types
|
||||
).execute().actionGet();
|
||||
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
|
||||
|
||||
|
@ -342,8 +352,9 @@ public class UpdateMappingIntegrationIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
public void testUpdateMappingOnAllTypes() throws IOException {
|
||||
assertTrue("remove this multi type test", Version.CURRENT.before(Version.fromString("7.0.0")));
|
||||
assertAcked(prepareCreate("index")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.setSettings("index.version.created", Version.V_5_6_0.id)
|
||||
.addMapping("type1", "f", "type=keyword").addMapping("type2", "f", "type=keyword"));
|
||||
|
||||
assertAcked(client().admin().indices().preparePutMapping("index")
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.indices.stats;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.DocWriteResponse;
|
||||
import org.elasticsearch.action.ShardOperationFailedException;
|
||||
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
|
||||
|
@ -53,14 +54,18 @@ import org.elasticsearch.index.translog.Translog;
|
|||
import org.elasticsearch.indices.IndicesQueryCache;
|
||||
import org.elasticsearch.indices.IndicesRequestCache;
|
||||
import org.elasticsearch.indices.IndicesService;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
||||
import org.elasticsearch.test.ESIntegTestCase.Scope;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
@ -90,6 +95,12 @@ import static org.hamcrest.Matchers.nullValue;
|
|||
@ClusterScope(scope = Scope.SUITE, numDataNodes = 2, numClientNodes = 0, randomDynamicTemplates = false)
|
||||
@SuppressCodecs("*") // requires custom completion format
|
||||
public class IndexStatsIT extends ESIntegTestCase {
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return Collections.singleton(InternalSettingsPlugin.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
//Filter/Query cache is cleaned periodically, default is 60s, so make sure it runs often. Thread.sleep for 60s is bad
|
||||
|
@ -378,7 +389,8 @@ public class IndexStatsIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
public void testSimpleStats() throws Exception {
|
||||
assertAcked(prepareCreate("test1").setSettings("index.mapping.single_type", false));
|
||||
// this test has some type stats tests that can be removed in 7.0
|
||||
assertAcked(prepareCreate("test1").setSettings("index.version.created", Version.V_5_6_0.id)); // allows for multiple types
|
||||
createIndex("test2");
|
||||
ensureGreen();
|
||||
|
||||
|
@ -508,7 +520,7 @@ public class IndexStatsIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
public void testMergeStats() {
|
||||
assertAcked(prepareCreate("test1").setSettings("index.mapping.single_type", false));
|
||||
assertAcked(prepareCreate("test_index"));
|
||||
|
||||
ensureGreen();
|
||||
|
||||
|
@ -530,8 +542,7 @@ public class IndexStatsIT extends ESIntegTestCase {
|
|||
assertThat(stats.getTotal().getSearch(), nullValue());
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
client().prepareIndex("test1", "type1", Integer.toString(i)).setSource("field", "value").execute().actionGet();
|
||||
client().prepareIndex("test1", "type2", Integer.toString(i)).setSource("field", "value").execute().actionGet();
|
||||
client().prepareIndex("test_index", "doc", Integer.toString(i)).setSource("field", "value").execute().actionGet();
|
||||
client().admin().indices().prepareFlush().execute().actionGet();
|
||||
}
|
||||
client().admin().indices().prepareForceMerge().setMaxNumSegments(1).execute().actionGet();
|
||||
|
@ -544,15 +555,14 @@ public class IndexStatsIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
public void testSegmentsStats() {
|
||||
assertAcked(prepareCreate("test1")
|
||||
.setSettings(SETTING_NUMBER_OF_REPLICAS, between(0, 1), "index.mapping.single_type", false));
|
||||
assertAcked(prepareCreate("test_index")
|
||||
.setSettings(SETTING_NUMBER_OF_REPLICAS, between(0, 1)));
|
||||
ensureGreen();
|
||||
|
||||
NumShards test1 = getNumShards("test1");
|
||||
NumShards test1 = getNumShards("test_index");
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
index("test1", "type1", Integer.toString(i), "field", "value");
|
||||
index("test1", "type2", Integer.toString(i), "field", "value");
|
||||
index("test_index", "doc", Integer.toString(i), "field", "value");
|
||||
}
|
||||
|
||||
IndicesStatsResponse stats = client().admin().indices().prepareStats().setSegments(true).get();
|
||||
|
@ -570,14 +580,14 @@ public class IndexStatsIT extends ESIntegTestCase {
|
|||
|
||||
public void testAllFlags() throws Exception {
|
||||
// rely on 1 replica for this tests
|
||||
assertAcked(prepareCreate("test1").setSettings("index.mapping.single_type", false));
|
||||
createIndex("test2");
|
||||
assertAcked(prepareCreate("test_index"));
|
||||
createIndex("test_index_2");
|
||||
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test1", "type1", Integer.toString(1)).setSource("field", "value").execute().actionGet();
|
||||
client().prepareIndex("test1", "type2", Integer.toString(1)).setSource("field", "value").execute().actionGet();
|
||||
client().prepareIndex("test2", "type", Integer.toString(1)).setSource("field", "value").execute().actionGet();
|
||||
client().prepareIndex("test_index", "doc", Integer.toString(1)).setSource("field", "value").execute().actionGet();
|
||||
client().prepareIndex("test_index", "doc", Integer.toString(2)).setSource("field", "value").execute().actionGet();
|
||||
client().prepareIndex("test_index_2", "type", Integer.toString(1)).setSource("field", "value").execute().actionGet();
|
||||
|
||||
client().admin().indices().prepareRefresh().execute().actionGet();
|
||||
IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();
|
||||
|
@ -692,14 +702,14 @@ public class IndexStatsIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
public void testMultiIndex() throws Exception {
|
||||
assertAcked(prepareCreate("test1").setSettings("index.mapping.single_type", false));
|
||||
assertAcked(prepareCreate("test1"));
|
||||
createIndex("test2");
|
||||
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test1", "type1", Integer.toString(1)).setSource("field", "value").execute().actionGet();
|
||||
client().prepareIndex("test1", "type2", Integer.toString(1)).setSource("field", "value").execute().actionGet();
|
||||
client().prepareIndex("test2", "type", Integer.toString(1)).setSource("field", "value").execute().actionGet();
|
||||
client().prepareIndex("test1", "doc", Integer.toString(1)).setSource("field", "value").execute().actionGet();
|
||||
client().prepareIndex("test1", "doc", Integer.toString(2)).setSource("field", "value").execute().actionGet();
|
||||
client().prepareIndex("test2", "doc", Integer.toString(1)).setSource("field", "value").execute().actionGet();
|
||||
refresh();
|
||||
|
||||
int numShards1 = getNumShards("test1").totalNumShards;
|
||||
|
@ -732,14 +742,14 @@ public class IndexStatsIT extends ESIntegTestCase {
|
|||
|
||||
public void testFieldDataFieldsParam() throws Exception {
|
||||
assertAcked(client().admin().indices().prepareCreate("test1")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.addMapping("type", "bar", "type=text,fielddata=true",
|
||||
.setSettings("index.version.created", Version.V_5_6_0.id)
|
||||
.addMapping("doc", "bar", "type=text,fielddata=true",
|
||||
"baz", "type=text,fielddata=true").get());
|
||||
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get();
|
||||
client().prepareIndex("test1", "baz", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get();
|
||||
client().prepareIndex("test1", "doc", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get();
|
||||
client().prepareIndex("test1", "doc", Integer.toString(2)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get();
|
||||
refresh();
|
||||
|
||||
client().prepareSearch("_all").addSort("bar", SortOrder.ASC).addSort("baz", SortOrder.ASC).execute().actionGet();
|
||||
|
@ -780,14 +790,12 @@ public class IndexStatsIT extends ESIntegTestCase {
|
|||
|
||||
public void testCompletionFieldsParam() throws Exception {
|
||||
assertAcked(prepareCreate("test1")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.addMapping(
|
||||
"bar",
|
||||
"doc",
|
||||
"{ \"properties\": { \"bar\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}},\"baz\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}}}}", XContentType.JSON));
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get();
|
||||
client().prepareIndex("test1", "baz", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get();
|
||||
client().prepareIndex("test1", "doc", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get();
|
||||
refresh();
|
||||
|
||||
IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.elasticsearch.indices.template;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.admin.indices.alias.Alias;
|
||||
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse;
|
||||
|
@ -37,13 +38,16 @@ import org.elasticsearch.common.xcontent.XContentType;
|
|||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.indices.InvalidAliasNameException;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
import org.junit.After;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -67,6 +71,11 @@ import static org.hamcrest.Matchers.nullValue;
|
|||
|
||||
public class SimpleIndexTemplateIT extends ESIntegTestCase {
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return Collections.singleton(InternalSettingsPlugin.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanupTemplates() {
|
||||
client().admin().indices().prepareDeleteTemplate("*").get();
|
||||
|
@ -383,7 +392,7 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
|
|||
.get();
|
||||
|
||||
assertAcked(prepareCreate("test_index")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.setSettings("index.version.created", Version.V_5_6_0.id) // allow for multiple version
|
||||
.addMapping("type1").addMapping("type2").addMapping("typeX").addMapping("typeY").addMapping("typeZ"));
|
||||
ensureGreen();
|
||||
|
||||
|
@ -431,8 +440,8 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
|
|||
" \"aliases\" : {\n" +
|
||||
" \"my_alias\" : {\n" +
|
||||
" \"filter\" : {\n" +
|
||||
" \"type\" : {\n" +
|
||||
" \"value\" : \"type2\"\n" +
|
||||
" \"term\" : {\n" +
|
||||
" \"field\" : \"value2\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
|
@ -441,16 +450,15 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
|
|||
|
||||
|
||||
assertAcked(prepareCreate("test_index")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.addMapping("type1").addMapping("type2"));
|
||||
.addMapping("doc"));
|
||||
ensureGreen();
|
||||
|
||||
GetAliasesResponse getAliasesResponse = client().admin().indices().prepareGetAliases().setIndices("test_index").get();
|
||||
assertThat(getAliasesResponse.getAliases().size(), equalTo(1));
|
||||
assertThat(getAliasesResponse.getAliases().get("test_index").size(), equalTo(1));
|
||||
|
||||
client().prepareIndex("test_index", "type1", "1").setSource("field", "value1").get();
|
||||
client().prepareIndex("test_index", "type2", "2").setSource("field", "value2").get();
|
||||
client().prepareIndex("test_index", "doc", "1").setSource("field", "value1").get();
|
||||
client().prepareIndex("test_index", "doc", "2").setSource("field", "value2").get();
|
||||
refresh();
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("test_index").get();
|
||||
|
@ -458,7 +466,7 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
|
|||
|
||||
searchResponse = client().prepareSearch("my_alias").get();
|
||||
assertHitCount(searchResponse, 1L);
|
||||
assertThat(searchResponse.getHits().getAt(0).getType(), equalTo("type2"));
|
||||
assertThat(searchResponse.getHits().getAt(0).getSourceAsMap().get("field"), equalTo("value2"));
|
||||
}
|
||||
|
||||
public void testIndexTemplateWithAliasesSource() {
|
||||
|
@ -469,8 +477,8 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
|
|||
" \"alias1\" : {},\n" +
|
||||
" \"alias2\" : {\n" +
|
||||
" \"filter\" : {\n" +
|
||||
" \"type\" : {\n" +
|
||||
" \"value\" : \"type2\"\n" +
|
||||
" \"term\" : {\n" +
|
||||
" \"field\" : \"value2\"\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
|
@ -478,16 +486,15 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
|
|||
" }\n").get();
|
||||
|
||||
assertAcked(prepareCreate("test_index")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.addMapping("type1").addMapping("type2"));
|
||||
.addMapping("doc"));
|
||||
ensureGreen();
|
||||
|
||||
GetAliasesResponse getAliasesResponse = client().admin().indices().prepareGetAliases().setIndices("test_index").get();
|
||||
assertThat(getAliasesResponse.getAliases().size(), equalTo(1));
|
||||
assertThat(getAliasesResponse.getAliases().get("test_index").size(), equalTo(3));
|
||||
|
||||
client().prepareIndex("test_index", "type1", "1").setSource("field", "value1").get();
|
||||
client().prepareIndex("test_index", "type2", "2").setSource("field", "value2").get();
|
||||
client().prepareIndex("test_index", "doc", "1").setSource("field", "value1").get();
|
||||
client().prepareIndex("test_index", "doc", "2").setSource("field", "value2").get();
|
||||
refresh();
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("test_index").get();
|
||||
|
@ -498,7 +505,7 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
|
|||
|
||||
searchResponse = client().prepareSearch("alias2").get();
|
||||
assertHitCount(searchResponse, 1L);
|
||||
assertThat(searchResponse.getHits().getAt(0).getType(), equalTo("type2"));
|
||||
assertThat(searchResponse.getHits().getAt(0).getSourceAsMap().get("field"), equalTo("value2"));
|
||||
}
|
||||
|
||||
public void testDuplicateAlias() throws Exception {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.search.child;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
|
||||
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
|
@ -60,7 +61,7 @@ public class ParentFieldLoadingIT extends ESIntegTestCase {
|
|||
.put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), -1)
|
||||
// We never want merges in this test to ensure we have two segments for the last validation
|
||||
.put(MergePolicyConfig.INDEX_MERGE_ENABLED, false)
|
||||
.put("index.mapping.single_type", false)
|
||||
.put("index.version.created", Version.V_5_6_0)
|
||||
.build();
|
||||
|
||||
public void testEagerParentFieldLoading() throws Exception {
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.search.fetch.subphase;
|
|||
|
||||
import org.apache.lucene.search.join.ScoreMode;
|
||||
import org.apache.lucene.util.ArrayUtil;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
||||
|
@ -40,8 +41,10 @@ import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
|||
import org.elasticsearch.search.sort.FieldSortBuilder;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -72,7 +75,7 @@ public class InnerHitsIT extends ESIntegTestCase {
|
|||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return Collections.singleton(CustomScriptPlugin.class);
|
||||
return Arrays.asList(InternalSettingsPlugin.class, CustomScriptPlugin.class);
|
||||
}
|
||||
|
||||
public static class CustomScriptPlugin extends MockScriptPlugin {
|
||||
|
@ -591,7 +594,7 @@ public class InnerHitsIT extends ESIntegTestCase {
|
|||
|
||||
public void testInnerHitsWithIgnoreUnmapped() throws Exception {
|
||||
assertAcked(prepareCreate("index1")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.setSettings("index.version.created", Version.V_5_6_0.id)
|
||||
.addMapping("parent_type", "nested_type", "type=nested")
|
||||
.addMapping("child_type", "_parent", "type=parent_type")
|
||||
);
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.elasticsearch.search.fetch.subphase.highlight;
|
|||
|
||||
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
|
||||
import org.apache.lucene.search.join.ScoreMode;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
|
@ -1358,29 +1359,27 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
public void testPhrasePrefix() throws IOException {
|
||||
Builder builder = Settings.builder()
|
||||
.put(indexSettings())
|
||||
.put("index.mapping.single_type", false)
|
||||
.put("index.analysis.analyzer.synonym.tokenizer", "whitespace")
|
||||
.putArray("index.analysis.analyzer.synonym.filter", "synonym", "lowercase")
|
||||
.put("index.analysis.filter.synonym.type", "synonym")
|
||||
.putArray("index.analysis.filter.synonym.synonyms", "quick => fast");
|
||||
|
||||
assertAcked(prepareCreate("test").setSettings(builder.build()).addMapping("type1", type1TermVectorMapping())
|
||||
.addMapping("type2",
|
||||
"field4", "type=text,term_vector=with_positions_offsets,analyzer=synonym",
|
||||
"field3", "type=text,analyzer=synonym"));
|
||||
assertAcked(prepareCreate("first_test_index").setSettings(builder.build()).addMapping("type1", type1TermVectorMapping()));
|
||||
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test", "type1", "0").setSource(
|
||||
client().prepareIndex("first_test_index", "type1", "0").setSource(
|
||||
"field0", "The quick brown fox jumps over the lazy dog",
|
||||
"field1", "The quick brown fox jumps over the lazy dog").get();
|
||||
client().prepareIndex("test", "type1", "1").setSource("field1", "The quick browse button is a fancy thing, right bro?").get();
|
||||
client().prepareIndex("first_test_index", "type1", "1").setSource("field1",
|
||||
"The quick browse button is a fancy thing, right bro?").get();
|
||||
refresh();
|
||||
logger.info("--> highlighting and searching on field0");
|
||||
|
||||
SearchSourceBuilder source = searchSource()
|
||||
.query(matchPhrasePrefixQuery("field0", "bro"))
|
||||
.highlighter(highlight().field("field0").order("score").preTags("<x>").postTags("</x>"));
|
||||
SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
SearchResponse searchResponse = client().search(searchRequest("first_test_index").source(source)).actionGet();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field0", 0, 1, equalTo("The quick <x>brown</x> fox jumps over the lazy dog"));
|
||||
|
||||
|
@ -1388,7 +1387,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
.query(matchPhrasePrefixQuery("field0", "quick bro"))
|
||||
.highlighter(highlight().field("field0").order("score").preTags("<x>").postTags("</x>"));
|
||||
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
searchResponse = client().search(searchRequest("first_test_index").source(source)).actionGet();
|
||||
assertHighlight(searchResponse, 0, "field0", 0, 1, equalTo("The <x>quick</x> <x>brown</x> fox jumps over the lazy dog"));
|
||||
|
||||
logger.info("--> highlighting and searching on field1");
|
||||
|
@ -1399,7 +1398,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
)
|
||||
.highlighter(highlight().field("field1").order("score").preTags("<x>").postTags("</x>"));
|
||||
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
searchResponse = client().search(searchRequest("first_test_index").source(source)).actionGet();
|
||||
assertThat(searchResponse.getHits().totalHits, equalTo(2L));
|
||||
for (int i = 0; i < 2; i++) {
|
||||
assertHighlight(searchResponse, i, "field1", 0, 1, anyOf(
|
||||
|
@ -1411,7 +1410,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
.query(matchPhrasePrefixQuery("field1", "quick bro"))
|
||||
.highlighter(highlight().field("field1").order("score").preTags("<x>").postTags("</x>"));
|
||||
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
searchResponse = client().search(searchRequest("first_test_index").source(source)).actionGet();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field1", 0, 1, anyOf(
|
||||
equalTo("The <x>quick</x> <x>browse</x> button is a fancy thing, right bro?"),
|
||||
|
@ -1420,27 +1419,33 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
equalTo("The <x>quick</x> <x>browse</x> button is a fancy thing, right bro?"),
|
||||
equalTo("The <x>quick</x> <x>brown</x> fox jumps over the lazy dog")));
|
||||
|
||||
assertAcked(prepareCreate("second_test_index").setSettings(builder.build()).addMapping("doc",
|
||||
"field4", "type=text,term_vector=with_positions_offsets,analyzer=synonym",
|
||||
"field3", "type=text,analyzer=synonym"));
|
||||
// with synonyms
|
||||
client().prepareIndex("test", "type2", "0").setSource(
|
||||
client().prepareIndex("second_test_index", "doc", "0").setSource(
|
||||
"type", "type2",
|
||||
"field4", "The quick brown fox jumps over the lazy dog",
|
||||
"field3", "The quick brown fox jumps over the lazy dog").get();
|
||||
client().prepareIndex("test", "type2", "1").setSource(
|
||||
client().prepareIndex("second_test_index", "doc", "1").setSource(
|
||||
"type", "type2",
|
||||
"field4", "The quick browse button is a fancy thing, right bro?").get();
|
||||
client().prepareIndex("test", "type2", "2").setSource(
|
||||
client().prepareIndex("second_test_index", "doc", "2").setSource(
|
||||
"type", "type2",
|
||||
"field4", "a quick fast blue car").get();
|
||||
refresh();
|
||||
|
||||
source = searchSource().postFilter(typeQuery("type2")).query(matchPhrasePrefixQuery("field3", "fast bro"))
|
||||
source = searchSource().postFilter(termQuery("type", "type2")).query(matchPhrasePrefixQuery("field3", "fast bro"))
|
||||
.highlighter(highlight().field("field3").order("score").preTags("<x>").postTags("</x>"));
|
||||
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
searchResponse = client().search(searchRequest("second_test_index").source(source)).actionGet();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field3", 0, 1, equalTo("The <x>quick</x> <x>brown</x> fox jumps over the lazy dog"));
|
||||
|
||||
logger.info("--> highlighting and searching on field4");
|
||||
source = searchSource().postFilter(typeQuery("type2")).query(matchPhrasePrefixQuery("field4", "the fast bro"))
|
||||
source = searchSource().postFilter(termQuery("type", "type2")).query(matchPhrasePrefixQuery("field4", "the fast bro"))
|
||||
.highlighter(highlight().field("field4").order("score").preTags("<x>").postTags("</x>"));
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
searchResponse = client().search(searchRequest("second_test_index").source(source)).actionGet();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field4", 0, 1, anyOf(
|
||||
equalTo("<x>The</x> <x>quick</x> <x>browse</x> button is a fancy thing, right bro?"),
|
||||
|
@ -1450,9 +1455,9 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
equalTo("<x>The</x> <x>quick</x> <x>brown</x> fox jumps over the lazy dog")));
|
||||
|
||||
logger.info("--> highlighting and searching on field4");
|
||||
source = searchSource().postFilter(typeQuery("type2")).query(matchPhrasePrefixQuery("field4", "a fast quick blue ca"))
|
||||
source = searchSource().postFilter(termQuery("type", "type2")).query(matchPhrasePrefixQuery("field4", "a fast quick blue ca"))
|
||||
.highlighter(highlight().field("field4").order("score").preTags("<x>").postTags("</x>"));
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
searchResponse = client().search(searchRequest("second_test_index").source(source)).actionGet();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field4", 0, 1,
|
||||
anyOf(equalTo("<x>a quick fast blue car</x>"),
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.search.fields;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
|
@ -43,6 +44,7 @@ import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|||
import org.elasticsearch.search.lookup.FieldLookup;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.ReadableDateTime;
|
||||
|
@ -81,7 +83,7 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
|||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return Collections.singletonList(CustomScriptPlugin.class);
|
||||
return Arrays.asList(InternalSettingsPlugin.class, CustomScriptPlugin.class);
|
||||
}
|
||||
|
||||
public static class CustomScriptPlugin extends MockScriptPlugin {
|
||||
|
@ -640,10 +642,9 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
|||
public void testGetFieldsComplexField() throws Exception {
|
||||
client().admin().indices().prepareCreate("my-index")
|
||||
.setSettings("index.refresh_interval", -1)
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.addMapping("my-type2", jsonBuilder()
|
||||
.addMapping("doc", jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("my-type2")
|
||||
.startObject("doc")
|
||||
.startObject("properties")
|
||||
.startObject("field1")
|
||||
.field("type", "object")
|
||||
|
@ -692,19 +693,12 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
|||
.endArray()
|
||||
.endObject().bytes();
|
||||
|
||||
client().prepareIndex("my-index", "my-type1", "1").setSource(source, XContentType.JSON).get();
|
||||
client().prepareIndex("my-index", "my-type2", "1").setRefreshPolicy(IMMEDIATE).setSource(source, XContentType.JSON).get();
|
||||
client().prepareIndex("my-index", "doc", "1").setRefreshPolicy(IMMEDIATE).setSource(source, XContentType.JSON).get();
|
||||
|
||||
|
||||
String field = "field1.field2.field3.field4";
|
||||
SearchResponse searchResponse = client().prepareSearch("my-index").setTypes("my-type1").addStoredField(field).get();
|
||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
|
||||
assertThat(searchResponse.getHits().getAt(0).field(field).isMetadataField(), equalTo(false));
|
||||
assertThat(searchResponse.getHits().getAt(0).field(field).getValues().size(), equalTo(2));
|
||||
assertThat(searchResponse.getHits().getAt(0).field(field).getValues().get(0).toString(), equalTo("value1"));
|
||||
assertThat(searchResponse.getHits().getAt(0).field(field).getValues().get(1).toString(), equalTo("value2"));
|
||||
|
||||
searchResponse = client().prepareSearch("my-index").setTypes("my-type2").addStoredField(field).get();
|
||||
SearchResponse searchResponse = client().prepareSearch("my-index").addStoredField(field).get();
|
||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
|
||||
assertThat(searchResponse.getHits().getAt(0).field(field).isMetadataField(), equalTo(false));
|
||||
assertThat(searchResponse.getHits().getAt(0).field(field).getValues().size(), equalTo(2));
|
||||
|
@ -871,15 +865,11 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
public void testLoadMetadata() throws Exception {
|
||||
assertAcked(prepareCreate("test")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.addMapping("parent")
|
||||
.addMapping("my-type1", "_parent", "type=parent"));
|
||||
assertAcked(prepareCreate("test"));
|
||||
|
||||
indexRandom(true,
|
||||
client().prepareIndex("test", "my-type1", "1")
|
||||
client().prepareIndex("test", "doc", "1")
|
||||
.setRouting("1")
|
||||
.setParent("parent_1")
|
||||
.setSource(jsonBuilder().startObject().field("field1", "value").endObject()));
|
||||
|
||||
SearchResponse response = client().prepareSearch("test").addStoredField("field1").get();
|
||||
|
@ -891,7 +881,5 @@ public class SearchFieldsIT extends ESIntegTestCase {
|
|||
assertThat(fields.get("field1"), nullValue());
|
||||
assertThat(fields.get("_routing").isMetadataField(), equalTo(true));
|
||||
assertThat(fields.get("_routing").getValue().toString(), equalTo("1"));
|
||||
assertThat(fields.get("_parent").isMetadataField(), equalTo(true));
|
||||
assertThat(fields.get("_parent").getValue().toString(), equalTo("parent_1"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.search.morelikethis;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
||||
|
@ -32,10 +33,14 @@ import org.elasticsearch.common.xcontent.XContentType;
|
|||
import org.elasticsearch.index.query.MoreLikeThisQueryBuilder;
|
||||
import org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
|
@ -58,6 +63,12 @@ import static org.hamcrest.Matchers.equalTo;
|
|||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
public class MoreLikeThisIT extends ESIntegTestCase {
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return Collections.singleton(InternalSettingsPlugin.class);
|
||||
}
|
||||
|
||||
public void testSimpleMoreLikeThis() throws Exception {
|
||||
logger.info("Creating index test");
|
||||
assertAcked(prepareCreate("test").addMapping("type1",
|
||||
|
@ -82,14 +93,13 @@ public class MoreLikeThisIT extends ESIntegTestCase {
|
|||
public void testSimpleMoreLikeOnLongField() throws Exception {
|
||||
logger.info("Creating index test");
|
||||
assertAcked(prepareCreate("test")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.addMapping("type1", "some_long", "type=long"));
|
||||
logger.info("Running Cluster Health");
|
||||
assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN));
|
||||
|
||||
logger.info("Indexing...");
|
||||
client().index(indexRequest("test").type("type1").id("1").source(jsonBuilder().startObject().field("some_long", 1367484649580L).endObject())).actionGet();
|
||||
client().index(indexRequest("test").type("type2").id("2").source(jsonBuilder().startObject().field("some_long", 0).endObject())).actionGet();
|
||||
client().index(indexRequest("test").type("type1").id("2").source(jsonBuilder().startObject().field("some_long", 0).endObject())).actionGet();
|
||||
client().index(indexRequest("test").type("type1").id("3").source(jsonBuilder().startObject().field("some_long", -666).endObject())).actionGet();
|
||||
|
||||
client().admin().indices().refresh(refreshRequest()).actionGet();
|
||||
|
@ -360,7 +370,7 @@ public class MoreLikeThisIT extends ESIntegTestCase {
|
|||
logger.info("Creating index test");
|
||||
int numOfTypes = randomIntBetween(2, 10);
|
||||
CreateIndexRequestBuilder createRequestBuilder = prepareCreate("test")
|
||||
.setSettings("index.mapping.single_type", false);
|
||||
.setSettings("index.version.created", Version.V_5_6_0.id);
|
||||
for (int i = 0; i < numOfTypes; i++) {
|
||||
createRequestBuilder.addMapping("type" + i, jsonBuilder().startObject().startObject("type" + i).startObject("properties")
|
||||
.startObject("text").field("type", "text").endObject()
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.search.query;
|
||||
|
||||
import org.apache.lucene.util.English;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
||||
|
@ -41,16 +42,20 @@ import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
|
|||
import org.elasticsearch.index.search.MatchQuery;
|
||||
import org.elasticsearch.index.search.MatchQuery.Type;
|
||||
import org.elasticsearch.indices.TermsLookup;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.format.ISODateTimeFormat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
|
@ -102,6 +107,11 @@ import static org.hamcrest.Matchers.is;
|
|||
|
||||
public class SearchQueryIT extends ESIntegTestCase {
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return Collections.singleton(InternalSettingsPlugin.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int maximumNumberOfShards() {
|
||||
return 7;
|
||||
|
@ -545,7 +555,7 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
public void testTypeFilter() throws Exception {
|
||||
assertAcked(prepareCreate("test").setSettings("index.mapping.single_type", false));
|
||||
assertAcked(prepareCreate("test").setSettings("index.version.created", Version.V_5_6_0.id));
|
||||
indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("field1", "value1"),
|
||||
client().prepareIndex("test", "type2", "1").setSource("field1", "value1"),
|
||||
client().prepareIndex("test", "type1", "2").setSource("field1", "value1"),
|
||||
|
@ -1181,7 +1191,36 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
public void testBasicQueryById() throws Exception {
|
||||
assertAcked(prepareCreate("test").setSettings("index.mapping.single_type", false));
|
||||
assertAcked(prepareCreate("test"));
|
||||
|
||||
client().prepareIndex("test", "doc", "1").setSource("field1", "value1").get();
|
||||
client().prepareIndex("test", "doc", "2").setSource("field1", "value2").get();
|
||||
client().prepareIndex("test", "doc", "3").setSource("field1", "value3").get();
|
||||
refresh();
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch().setQuery(idsQuery("doc").addIds("1", "2")).get();
|
||||
assertHitCount(searchResponse, 2L);
|
||||
assertThat(searchResponse.getHits().getHits().length, equalTo(2));
|
||||
|
||||
searchResponse = client().prepareSearch().setQuery(idsQuery().addIds("1")).get();
|
||||
assertHitCount(searchResponse, 1L);
|
||||
assertThat(searchResponse.getHits().getHits().length, equalTo(1));
|
||||
|
||||
searchResponse = client().prepareSearch().setQuery(idsQuery().addIds("1", "2")).get();
|
||||
assertHitCount(searchResponse, 2L);
|
||||
assertThat(searchResponse.getHits().getHits().length, equalTo(2));
|
||||
|
||||
searchResponse = client().prepareSearch().setQuery(idsQuery(Strings.EMPTY_ARRAY).addIds("1")).get();
|
||||
assertHitCount(searchResponse, 1L);
|
||||
assertThat(searchResponse.getHits().getHits().length, equalTo(1));
|
||||
|
||||
searchResponse = client().prepareSearch().setQuery(idsQuery("type1", "type2", "doc").addIds("1", "2", "3", "4")).get();
|
||||
assertHitCount(searchResponse, 3L);
|
||||
assertThat(searchResponse.getHits().getHits().length, equalTo(3));
|
||||
}
|
||||
|
||||
public void testBasicQueryByIdMultiType() throws Exception {
|
||||
assertAcked(prepareCreate("test").setSettings("index.version.created", Version.V_5_6_0.id));
|
||||
|
||||
client().prepareIndex("test", "type1", "1").setSource("field1", "value1").get();
|
||||
client().prepareIndex("test", "type2", "2").setSource("field1", "value2").get();
|
||||
|
@ -1212,6 +1251,7 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
assertThat(searchResponse.getHits().getHits().length, equalTo(2));
|
||||
}
|
||||
|
||||
|
||||
public void testNumericTermsAndRanges() throws Exception {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1",
|
||||
|
@ -1448,10 +1488,9 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
|
||||
public void testSimpleDFSQuery() throws IOException {
|
||||
assertAcked(prepareCreate("test")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.addMapping("s", jsonBuilder()
|
||||
.addMapping("doc", jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("s")
|
||||
.startObject("doc")
|
||||
.startObject("_routing")
|
||||
.field("required", true)
|
||||
.endObject()
|
||||
|
@ -1470,13 +1509,17 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
.endObject()
|
||||
.endObject()
|
||||
.endObject())
|
||||
.addMapping("bs", "online", "type=boolean", "ts", "type=date,ignore_malformed=false,format=epoch_millis"));
|
||||
);
|
||||
|
||||
|
||||
client().prepareIndex("test", "s", "1").setRouting("Y").setSource("online", false, "bs", "Y", "ts", System.currentTimeMillis() - 100).get();
|
||||
client().prepareIndex("test", "s", "2").setRouting("X").setSource("online", true, "bs", "X", "ts", System.currentTimeMillis() - 10000000).get();
|
||||
client().prepareIndex("test", "bs", "3").setSource("online", false, "ts", System.currentTimeMillis() - 100).get();
|
||||
client().prepareIndex("test", "bs", "4").setSource("online", true, "ts", System.currentTimeMillis() - 123123).get();
|
||||
client().prepareIndex("test", "doc", "1").setRouting("Y").setSource("online", false, "bs", "Y", "ts",
|
||||
System.currentTimeMillis() - 100, "type", "s").get();
|
||||
client().prepareIndex("test", "doc", "2").setRouting("X").setSource("online", true, "bs", "X", "ts",
|
||||
System.currentTimeMillis() - 10000000, "type", "s").get();
|
||||
client().prepareIndex("test", "doc", "3").setRouting(randomAlphaOfLength(2))
|
||||
.setSource("online", false, "ts", System.currentTimeMillis() - 100, "type", "bs").get();
|
||||
client().prepareIndex("test", "doc", "4").setRouting(randomAlphaOfLength(2))
|
||||
.setSource("online", true, "ts", System.currentTimeMillis() - 123123, "type", "bs").get();
|
||||
refresh();
|
||||
|
||||
SearchResponse response = client().prepareSearch("test")
|
||||
|
@ -1487,11 +1530,11 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
.must(boolQuery()
|
||||
.should(boolQuery()
|
||||
.must(rangeQuery("ts").lt(System.currentTimeMillis() - (15 * 1000)))
|
||||
.must(termQuery("_type", "bs"))
|
||||
.must(termQuery("type", "bs"))
|
||||
)
|
||||
.should(boolQuery()
|
||||
.must(rangeQuery("ts").lt(System.currentTimeMillis() - (15 * 1000)))
|
||||
.must(termQuery("_type", "s"))
|
||||
.must(termQuery("type", "s"))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -1620,29 +1663,33 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
public void testQueryStringWithSlopAndFields() {
|
||||
assertAcked(prepareCreate("test").setSettings("index.mapping.single_type", false));
|
||||
assertAcked(prepareCreate("test"));
|
||||
|
||||
client().prepareIndex("test", "customer", "1").setSource("desc", "one two three").get();
|
||||
client().prepareIndex("test", "product", "2").setSource("desc", "one two three").get();
|
||||
client().prepareIndex("test", "doc", "1").setSource("desc", "one two three", "type", "customer").get();
|
||||
client().prepareIndex("test", "doc", "2").setSource("desc", "one two three", "type", "product").get();
|
||||
refresh();
|
||||
{
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryStringQuery("\"one two\"").defaultField("desc")).get();
|
||||
assertHitCount(searchResponse, 2);
|
||||
}
|
||||
{
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setTypes("product").setQuery(QueryBuilders.queryStringQuery("\"one two\"").field("desc")).get();
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setPostFilter(QueryBuilders.termQuery("type", "customer"))
|
||||
.setQuery(QueryBuilders.queryStringQuery("\"one two\"").field("desc")).get();
|
||||
assertHitCount(searchResponse, 1);
|
||||
}
|
||||
{
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setTypes("product").setQuery(QueryBuilders.queryStringQuery("\"one three\"~5").field("desc")).get();
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setPostFilter(QueryBuilders.termQuery("type", "product"))
|
||||
.setQuery(QueryBuilders.queryStringQuery("\"one three\"~5").field("desc")).get();
|
||||
assertHitCount(searchResponse, 1);
|
||||
}
|
||||
{
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setTypes("customer").setQuery(QueryBuilders.queryStringQuery("\"one two\"").defaultField("desc")).get();
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setPostFilter(QueryBuilders.termQuery("type", "customer"))
|
||||
.setQuery(QueryBuilders.queryStringQuery("\"one two\"").defaultField("desc")).get();
|
||||
assertHitCount(searchResponse, 1);
|
||||
}
|
||||
{
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setTypes("customer").setQuery(QueryBuilders.queryStringQuery("\"one two\"").defaultField("desc")).get();
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setPostFilter(QueryBuilders.termQuery("type", "customer"))
|
||||
.setQuery(QueryBuilders.queryStringQuery("\"one two\"").defaultField("desc")).get();
|
||||
assertHitCount(searchResponse, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -386,10 +386,10 @@ public class TribeIT extends ESIntegTestCase {
|
|||
public void testTribeOnOneCluster() throws Exception {
|
||||
try (Releasable tribeNode = startTribeNode()) {
|
||||
// Creates 2 indices, test1 on cluster1 and test2 on cluster2
|
||||
assertAcked(cluster1.client().admin().indices().prepareCreate("test1").setSettings("index.mapping.single_type", false));
|
||||
assertAcked(cluster1.client().admin().indices().prepareCreate("test1"));
|
||||
ensureGreen(cluster1.client());
|
||||
|
||||
assertAcked(cluster2.client().admin().indices().prepareCreate("test2").setSettings("index.mapping.single_type", false));
|
||||
assertAcked(cluster2.client().admin().indices().prepareCreate("test2"));
|
||||
ensureGreen(cluster2.client());
|
||||
|
||||
// Wait for the tribe node to retrieve the indices into its cluster state
|
||||
|
@ -411,21 +411,6 @@ public class TribeIT extends ESIntegTestCase {
|
|||
assertThat(clusterState.getMetaData().index("test2").mapping("type1"), notNullValue());
|
||||
});
|
||||
|
||||
// More documents with another type
|
||||
indexRandom(true,
|
||||
client().prepareIndex("test1", "type2", "1").setSource("field1", "value1"),
|
||||
client().prepareIndex("test2", "type2", "1").setSource("field1", "value1")
|
||||
);
|
||||
assertHitCount(client().prepareSearch().get(), 4L);
|
||||
assertBusy(() -> {
|
||||
ClusterState clusterState = client().admin().cluster().prepareState().get().getState();
|
||||
assertThat(clusterState.getMetaData().index("test1").mapping("type1"), notNullValue());
|
||||
assertThat(clusterState.getMetaData().index("test1").mapping("type2"), notNullValue());
|
||||
|
||||
assertThat(clusterState.getMetaData().index("test2").mapping("type1"), notNullValue());
|
||||
assertThat(clusterState.getMetaData().index("test2").mapping("type2"), notNullValue());
|
||||
});
|
||||
|
||||
// Make sure master level write operations fail... (we don't really have a master)
|
||||
expectThrows(MasterNotDiscoveredException.class, () -> {
|
||||
client().admin().indices().prepareCreate("tribe_index").setMasterNodeTimeout("10ms").get();
|
||||
|
|
|
@ -33,6 +33,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.function.Function;
|
||||
|
||||
import org.elasticsearch.ElasticsearchTimeoutException;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.DocWriteResponse;
|
||||
|
@ -272,7 +273,7 @@ public class UpdateIT extends ESIntegTestCase {
|
|||
assertThat(updateResponse.getGetResult().sourceAsMap().get("bar").toString(), equalTo("baz"));
|
||||
assertThat(updateResponse.getGetResult().sourceAsMap().get("extra").toString(), equalTo("foo"));
|
||||
}
|
||||
|
||||
|
||||
public void testIndexAutoCreation() throws Exception {
|
||||
UpdateResponse updateResponse = client().prepareUpdate("test", "type1", "1")
|
||||
.setUpsert(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject())
|
||||
|
@ -461,7 +462,7 @@ public class UpdateIT extends ESIntegTestCase {
|
|||
|
||||
public void testContextVariables() throws Exception {
|
||||
assertAcked(prepareCreate("test")
|
||||
.setSettings("index.mapping.single_type", false)
|
||||
.setSettings("index.version.created", Version.V_5_6_0.id)
|
||||
.addAlias(new Alias("alias"))
|
||||
.addMapping("type1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
|
|
Loading…
Reference in New Issue