Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
* settings when it is first used, when it is referenced via its alias.
*/
public void testSystemIndexIsAutoCreatedViaAlias() {
doCreateTest(() -> indexDoc(INDEX_NAME, "1", "foo", "bar"), PRIMARY_INDEX_NAME);
doCreateTest(() -> indexDoc(INDEX_NAME, "1", "foo", "bar"), PRIMARY_INDEX_NAME, false);
}

/**
Expand All @@ -93,7 +93,7 @@ public void testSystemIndexIsAutoCreatedViaAlias() {
* index name.
*/
public void testSystemIndexIsAutoCreatedViaConcreteName() {
doCreateTest(() -> indexDoc(PRIMARY_INDEX_NAME, "1", "foo", "bar"), PRIMARY_INDEX_NAME);
doCreateTest(() -> indexDoc(PRIMARY_INDEX_NAME, "1", "foo", "bar"), PRIMARY_INDEX_NAME, false);
}

/**
Expand Down Expand Up @@ -144,7 +144,7 @@ public void testNonPrimarySystemIndexCreationThrowsError() {
* settings when it is explicitly created, when it is referenced via its alias.
*/
public void testCreateSystemIndexViaAlias() {
doCreateTest(() -> assertAcked(prepareCreate(INDEX_NAME)), PRIMARY_INDEX_NAME);
doCreateTest(() -> assertAcked(prepareCreate(INDEX_NAME)), PRIMARY_INDEX_NAME, false);
}

/**
Expand All @@ -153,7 +153,11 @@ public void testCreateSystemIndexViaAlias() {
* concrete index name.
*/
public void testCreateSystemIndexViaConcreteName() {
doCreateTest(() -> assertAcked(prepareCreate(PRIMARY_INDEX_NAME)), PRIMARY_INDEX_NAME);
doCreateTest(() -> assertAcked(prepareCreate(PRIMARY_INDEX_NAME)), PRIMARY_INDEX_NAME, false);
}

public void testSystemIndexIsAutoCreatedWithDynamicDefault() {
doCreateTest(() -> indexDoc(PRIMARY_INDEX_NAME, "1", "vector", new int[] { 1, 2, 3 }), PRIMARY_INDEX_NAME, true);
}

private void createSystemAliasViaV1Template(String indexName, String primaryIndexName) throws Exception {
Expand Down Expand Up @@ -265,12 +269,12 @@ public void testCreateSystemAliasViaComposableTemplateWithAllowsTemplates() thro
);
}

private void doCreateTest(Runnable runnable, String concreteIndex) {
private void doCreateTest(Runnable runnable, String concreteIndex, boolean expandVectorDefault) {
// Trigger the creation of the system index
runnable.run();
ensureGreen(INDEX_NAME);

assertMappingsAndSettings(TestSystemIndexDescriptor.getOldMappings(), concreteIndex);
assertMappingsAndSettings(TestSystemIndexDescriptor.getOldMappings(expandVectorDefault), concreteIndex);

// Remove the index and alias...
assertAcked(indicesAdmin().prepareAliases(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT).removeAlias(concreteIndex, INDEX_NAME).get());
Expand All @@ -283,7 +287,7 @@ private void doCreateTest(Runnable runnable, String concreteIndex) {
runnable.run();
ensureGreen(INDEX_NAME);

assertMappingsAndSettings(TestSystemIndexDescriptor.getNewMappings(), concreteIndex);
assertMappingsAndSettings(TestSystemIndexDescriptor.getNewMappings(expandVectorDefault), concreteIndex);
assertAliases(concreteIndex);
}

Expand Down Expand Up @@ -362,7 +366,7 @@ private void assertMappingsAndSettings(String expectedMappings, String concreteI
);
final Map<String, Object> sourceAsMap = mappings.get(concreteIndex).getSourceAsMap();

assertThat(sourceAsMap, equalTo(XContentHelper.convertToMap(XContentType.JSON.xContent(), expectedMappings, false)));
assertThat(sourceAsMap, equalTo(XContentHelper.convertToMap(XContentType.JSON.xContent(), expectedMappings, true)));

final GetSettingsResponse getSettingsResponse = indicesAdmin().getSettings(
new GetSettingsRequest(TEST_REQUEST_TIMEOUT).indices(INDEX_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public MappingsVersion getMappingsVersion() {
}

public static String getOldMappings() {
return getOldMappings(false);
}

public static String getOldMappings(boolean includeVectorDims) {
try {
final XContentBuilder builder = jsonBuilder();

Expand All @@ -112,6 +116,18 @@ public static String getOldMappings() {
builder.startObject("foo");
builder.field("type", "text");
builder.endObject();

builder.startObject("vector");
builder.field("type", "dense_vector");
if (includeVectorDims) {
builder.field("dims", 3);
}
builder.field("index", true);
builder.field("similarity", "cosine");
builder.startObject("index_options");
builder.field("type", "flat");
builder.endObject();
builder.endObject();
}
builder.endObject();
}
Expand All @@ -124,6 +140,10 @@ public static String getOldMappings() {
}

public static String getNewMappings() {
return getNewMappings(false);
}

public static String getNewMappings(boolean includeVectorDims) {
try {
final XContentBuilder builder = jsonBuilder();

Expand All @@ -142,6 +162,18 @@ public static String getNewMappings() {
builder.startObject("foo");
builder.field("type", "text");
builder.endObject();

builder.startObject("vector");
builder.field("type", "dense_vector");
if (includeVectorDims) {
builder.field("dims", 3);
}
builder.field("index", true);
builder.field("similarity", "cosine");
builder.startObject("index_options");
builder.field("type", "flat");
builder.endObject();
builder.endObject();
}
builder.endObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ protected void sendUpdateMapping(Index index, Mapping mappingUpdate, ActionListe
putMappingRequest.source(mappingUpdate.toString(), XContentType.JSON);
putMappingRequest.masterNodeTimeout(dynamicMappingUpdateTimeout);
putMappingRequest.ackTimeout(TimeValue.ZERO);
putMappingRequest.origin("bulk");
client.execute(
TransportAutoPutMappingAction.TYPE,
putMappingRequest,
Expand Down