org.elasticsearch.script.ScriptException Java Examples

The following examples show how to use org.elasticsearch.script.ScriptException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FeatureVectorScoringSearchScript.java    From elasticsearch-feature-vector-scoring with Apache License 2.0 6 votes vote down vote up
private FeatureVectorScoringSearchScript(Map<String, Object> params) throws ScriptException {
    this.field = (String) params.get("field");
    String inputFeatureVectorStr = (String) params.get("inputFeatureVector");
    if (this.field == null || inputFeatureVectorStr == null || inputFeatureVectorStr.trim().length() == 0) {
        return;
    }

    this.version = (String) params.get("version");
    this.baseConstant = params.get("baseConstant") != null ? Double.parseDouble(params.get("baseConstant").toString()) : DEFAULT_BASE_CONSTANT;
    this.factorConstant = params.get("factorConstant") != null ? Double.parseDouble(params.get("factorConstant").toString()) : DEFAULT_FACTOR_CONSTANT;

    String[] inputFeatureVectorArr = inputFeatureVectorStr.split(",");
    int dimension = inputFeatureVectorArr.length;
    double sumOfSquare = 0.0D;
    this.inputFeatureVector = new double[dimension];
    double temp;
    for (int index = 0; index < dimension; index++) {
        temp = Double.parseDouble(inputFeatureVectorArr[index].trim());
        this.inputFeatureVector[index] = temp;
        sumOfSquare += temp * temp;
    }

    this.inputFeatureVectorNorm = Math.sqrt(sumOfSquare);
}
 
Example #2
Source File: MustacheScriptEngineService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public Object run() {
    BytesStreamOutput result = new BytesStreamOutput();
    try (UTF8StreamWriter writer = utf8StreamWriter().setOutput(result)) {
        ((Mustache) template.compiled()).execute(writer, vars);
    } catch (Exception e) {
        logger.error("Error running " + template, e);
        throw new ScriptException("Error running " + template, e);
    }
    return result.bytes();
}
 
Example #3
Source File: Scripting.java    From elasticsearch-learning-to-rank with Apache License 2.0 5 votes vote down vote up
private static ScriptException convertToScriptException(String message, String source, String portion, Throwable cause) {
    List<String> stack = new ArrayList<>();
    stack.add(portion);
    StringBuilder pointer = new StringBuilder();
    if (cause instanceof ParseException) {
        int offset = ((ParseException) cause).getErrorOffset();
        for (int i = 0; i < offset; i++) {
            pointer.append(' ');
        }
    }
    pointer.append("^---- HERE");
    stack.add(pointer.toString());
    throw new ScriptException(message, cause, stack, source, "STATIC_COMPILER");
}
 
Example #4
Source File: FeatureVectorScoringSearchScript.java    From elasticsearch-feature-vector-scoring with Apache License 2.0 4 votes vote down vote up
@Override
public ExecutableScript newScript(@Nullable Map<String, Object> params) throws ScriptException {
    return new FeatureVectorScoringSearchScript(params);
}
 
Example #5
Source File: VectorScoreScript.java    From fast-elasticsearch-vector-scoring with Apache License 2.0 2 votes vote down vote up
/**
 * This method is called for every search on every shard.
 * 
 * @param params
 *            list of script parameters passed with the query
 * @return new native script
 */
public ExecutableScript newScript(@Nullable Map<String, Object> params) throws ScriptException {
    return new VectorScoreScript(params);
}