|
35 | 35 | import org.elasticsearch.common.CheckedBiFunction; |
36 | 36 | import org.elasticsearch.common.Numbers; |
37 | 37 | import org.elasticsearch.common.Strings; |
| 38 | +import org.elasticsearch.common.bytes.BytesArray; |
38 | 39 | import org.elasticsearch.common.bytes.BytesReference; |
39 | 40 | import org.elasticsearch.common.bytes.CompositeBytesReference; |
40 | 41 | import org.elasticsearch.common.regex.Regex; |
@@ -1222,11 +1223,14 @@ private static <T> List<T> handleHits( |
1222 | 1223 | private static BytesReference getDefinitionFromDocs(List<TrainedModelDefinitionDoc> docs, String modelId) |
1223 | 1224 | throws ElasticsearchException { |
1224 | 1225 |
|
1225 | | - BytesReference[] bb = new BytesReference[docs.size()]; |
1226 | | - for (int i = 0; i < docs.size(); i++) { |
1227 | | - bb[i] = docs.get(i).getBinaryData(); |
1228 | | - } |
1229 | | - BytesReference bytes = CompositeBytesReference.of(bb); |
| 1226 | + // If the user requested the compressed data string, we need access to the underlying bytes. |
| 1227 | + // BytesArray gives us that access. |
| 1228 | + BytesReference bytes = docs.size() == 1 |
| 1229 | + ? docs.get(0).getBinaryData() |
| 1230 | + : new BytesArray( |
| 1231 | + CompositeBytesReference.of(docs.stream().map(TrainedModelDefinitionDoc::getBinaryData).toArray(BytesReference[]::new)) |
| 1232 | + .toBytesRef() |
| 1233 | + ); |
1230 | 1234 |
|
1231 | 1235 | if (docs.get(0).getTotalDefinitionLength() != null) { |
1232 | 1236 | if (bytes.length() != docs.get(0).getTotalDefinitionLength()) { |
@@ -1264,7 +1268,6 @@ private TrainedModelConfig.Builder parseModelConfigLenientlyFromSource(BytesRefe |
1264 | 1268 | // lang ident model were the only models supported. Models created after |
1265 | 1269 | // VERSION_3RD_PARTY_CONFIG_ADDED must have modelType set, if not set modelType |
1266 | 1270 | // is a tree ensemble |
1267 | | - assert builder.getVersion().before(TrainedModelConfig.VERSION_3RD_PARTY_CONFIG_ADDED); |
1268 | 1271 | builder.setModelType(TrainedModelType.TREE_ENSEMBLE); |
1269 | 1272 | } |
1270 | 1273 | return builder; |
|
0 commit comments