Skip to content

Commit

Permalink
Fix merge with feature branch
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest committed Apr 1, 2024
1 parent b17d584 commit 82ffb5b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ private Map<String, List<FieldInferenceRequest>> createFieldInferenceRequests(Bu
for (var entry : fieldInferenceMap.values()) {
String field = entry.getName();
String inferenceId = entry.getInferenceId();
for (var sourceField : entry.getValue().sourceFields()) {
for (var sourceField : entry.getSourceFields()) {
Object inferenceResult = inferenceMap.remove(field);
var value = XContentMapValues.extractValue(sourceField, docMap);
if (value == null) {
Expand All @@ -435,7 +435,10 @@ private Map<String, List<FieldInferenceRequest>> createFieldInferenceRequests(Bu
}
ensureResponseAccumulatorSlot(item.id());
if (value instanceof String valueStr) {
List<FieldInferenceRequest> fieldRequests = fieldRequestsMap.computeIfAbsent(inferenceId, k -> new ArrayList<>());
List<FieldInferenceRequest> fieldRequests = fieldRequestsMap.computeIfAbsent(
inferenceId,
k -> new ArrayList<>()
);
fieldRequests.add(new FieldInferenceRequest(item.id(), field, valueStr));
} else {
addInferenceResponseFailure(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.xpack.inference.InferencePlugin;
import org.hamcrest.Matchers;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import static org.hamcrest.CoreMatchers.equalTo;

Expand Down Expand Up @@ -56,7 +57,6 @@ public void testSingleSourceSemanticTextField() throws Exception {
assertEquals(resultingState.metadata().index("test").getInferenceFields().get("field").getInferenceId(), "test_model");
}


public void testCopyToSemanticTextField() throws Exception {
final IndexService indexService = createIndex("test", client().admin().indices().prepareCreate("test"));
final MetadataMappingService mappingService = getInstanceFromNode(MetadataMappingService.class);
Expand Down Expand Up @@ -88,11 +88,12 @@ public void testCopyToSemanticTextField() throws Exception {
singleTask(request)
);
IndexMetadata indexMetadata = resultingState.metadata().index("test");
FieldInferenceMetadata.FieldInferenceOptions fieldInferenceOptions = indexMetadata.getFieldInferenceMetadata()
.getFieldInferenceOptions()
.get("semantic");
assertThat(fieldInferenceOptions.inferenceId(), equalTo("test_model"));
assertThat(fieldInferenceOptions.sourceFields(), equalTo(Set.of("semantic", "copy_origin_1", "copy_origin_2")));
InferenceFieldMetadata inferenceFieldMetadata = indexMetadata.getInferenceFields().get("semantic");
assertThat(inferenceFieldMetadata.getInferenceId(), equalTo("test_model"));
assertThat(
Arrays.asList(inferenceFieldMetadata.getSourceFields()),
Matchers.containsInAnyOrder("semantic", "copy_origin_1", "copy_origin_2")
);
}

private static List<MetadataMappingService.PutMappingClusterStateUpdateTask> singleTask(PutMappingClusterStateUpdateRequest request) {
Expand Down

0 comments on commit 82ffb5b

Please sign in to comment.