|
4 | 4 | */ |
5 | 5 | package org.opensearch.ml.processor; |
6 | 6 |
|
7 | | -import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken; |
8 | | -import static org.opensearch.ml.common.utils.StringUtils.toJson; |
9 | | -import static org.opensearch.ml.processor.InferenceProcessorAttributes.INPUT_MAP; |
10 | | -import static org.opensearch.ml.processor.InferenceProcessorAttributes.MAX_PREDICTION_TASKS; |
11 | | -import static org.opensearch.ml.processor.InferenceProcessorAttributes.MODEL_CONFIG; |
12 | | -import static org.opensearch.ml.processor.InferenceProcessorAttributes.MODEL_ID; |
13 | | -import static org.opensearch.ml.processor.InferenceProcessorAttributes.OUTPUT_MAP; |
14 | | -import static org.opensearch.ml.processor.ModelExecutor.combineMaps; |
15 | | - |
16 | | -import java.io.IOException; |
17 | | -import java.util.Collection; |
18 | | -import java.util.HashMap; |
19 | | -import java.util.HashSet; |
20 | | -import java.util.List; |
21 | | -import java.util.Map; |
22 | | -import java.util.Set; |
23 | | - |
| 7 | +import com.google.gson.Gson; |
| 8 | +import com.jayway.jsonpath.Configuration; |
| 9 | +import com.jayway.jsonpath.JsonPath; |
| 10 | +import com.jayway.jsonpath.Option; |
| 11 | +import com.jayway.jsonpath.PathNotFoundException; |
| 12 | +import com.jayway.jsonpath.ReadContext; |
| 13 | +import lombok.Getter; |
24 | 14 | import org.apache.commons.text.StringSubstitutor; |
25 | 15 | import org.apache.logging.log4j.LogManager; |
26 | 16 | import org.apache.logging.log4j.Logger; |
|
46 | 36 | import org.opensearch.search.pipeline.SearchRequestProcessor; |
47 | 37 | import org.opensearch.transport.client.Client; |
48 | 38 |
|
49 | | -import com.jayway.jsonpath.Configuration; |
50 | | -import com.jayway.jsonpath.JsonPath; |
51 | | -import com.jayway.jsonpath.Option; |
52 | | -import com.jayway.jsonpath.PathNotFoundException; |
53 | | -import com.jayway.jsonpath.ReadContext; |
| 39 | +import java.io.IOException; |
| 40 | +import java.util.Collection; |
| 41 | +import java.util.HashMap; |
| 42 | +import java.util.HashSet; |
| 43 | +import java.util.List; |
| 44 | +import java.util.Map; |
| 45 | +import java.util.Set; |
54 | 46 |
|
55 | | -import lombok.Getter; |
| 47 | +import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken; |
| 48 | +import static org.opensearch.ml.common.utils.StringUtils.toJson; |
| 49 | +import static org.opensearch.ml.processor.InferenceProcessorAttributes.INPUT_MAP; |
| 50 | +import static org.opensearch.ml.processor.InferenceProcessorAttributes.MAX_PREDICTION_TASKS; |
| 51 | +import static org.opensearch.ml.processor.InferenceProcessorAttributes.MODEL_CONFIG; |
| 52 | +import static org.opensearch.ml.processor.InferenceProcessorAttributes.MODEL_ID; |
| 53 | +import static org.opensearch.ml.processor.InferenceProcessorAttributes.OUTPUT_MAP; |
| 54 | +import static org.opensearch.ml.processor.ModelExecutor.combineMaps; |
56 | 55 |
|
57 | 56 | /** |
58 | 57 | * MLInferenceSearchRequestProcessor requires a modelId string to call model inferences |
@@ -360,6 +359,9 @@ private String updateQueryTemplate(String queryTemplate, Map<String, String> out |
360 | 359 | String newQueryField = outputMapEntry.getKey(); |
361 | 360 | String modelOutputFieldName = outputMapEntry.getValue(); |
362 | 361 | Object modelOutputValue = getModelOutputValue(mlOutput, modelOutputFieldName, ignoreMissing, fullResponsePath); |
| 362 | + if (modelOutputValue instanceof Map) { |
| 363 | + modelOutputValue = new Gson().toJson(modelOutputValue); |
| 364 | + } |
363 | 365 | valuesMap.put(newQueryField, modelOutputValue); |
364 | 366 | } |
365 | 367 | StringSubstitutor sub = new StringSubstitutor(valuesMap); |
|
0 commit comments