Skip to content

Commit

Permalink
Add copy_to support
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest committed Mar 22, 2024
1 parent c80677f commit 5896c60
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ public SourceLoader.SyntheticFieldLoader syntheticFieldLoader() {
return SourceLoader.SyntheticFieldLoader.NOTHING;
}

@SuppressWarnings("unchecked")
public static void applyFieldInference(
Map<String, Object> inferenceMap,
String field,
Expand All @@ -387,9 +388,10 @@ public static void applyFieldInference(
results.getWriteableName()
);
}
Map<String, Object> fieldMap = new LinkedHashMap<>();

Map<String, Object> fieldMap = (Map<String, Object>) inferenceMap.computeIfAbsent(field, s -> new LinkedHashMap<>());
fieldMap.putAll(new SemanticTextModelSettings(model).asMap());
fieldMap.put(InferenceResultFieldMapper.RESULTS, chunks);
inferenceMap.put(field, fieldMap);
List<Map<String, Object>> fieldChunks = (List<Map<String, Object>>) fieldMap.computeIfAbsent(InferenceResultFieldMapper.RESULTS, k -> new ArrayList<>());
fieldChunks.addAll(chunks);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,38 @@ setup:
- exists: _source._inference.top_level_field\.semantic_multifield.results.0.inference


---
"semantic_text copy_to calculate inference for source fields":
- do:
indices.create:
index: test-copy-to-index
body:
mappings:
properties:
inference_field:
type: semantic_text
model_id: dense-inference-id
source_field:
type: text
copy_to: inference_field

- do:
index:
index: test-copy-to-index
id: doc_1
body:
source_field: "copy_to inference test"
inference_field: "inference test"

- do:
get:
index: test-copy-to-index
id: doc_1

- match: { _source.inference_field: "inference test" }
- length: {_source._inference.inference_field.results: 2}
- match: { _source._inference.inference_field.results.0.text: "inference test" }
- match: { _source._inference.inference_field.results.1.text: "copy_to inference test" }

- exists: _source._inference.inference_field.results.0.inference
- exists: _source._inference.inference_field.results.1.inference

0 comments on commit 5896c60

Please sign in to comment.