Skip to content

Instantly share code, notes, and snippets.

@tsxn26
Created June 16, 2011 23:53
Show Gist options
  • Save tsxn26/1030597 to your computer and use it in GitHub Desktop.
Save tsxn26/1030597 to your computer and use it in GitHub Desktop.
Elastic Search Custom Script
package com.thomas;
import org.elasticsearch.script.AbstractFloatSearchScript;
import static java.lang.Math.max;
import static java.lang.Math.pow;
/**
* Created by IntelliJ IDEA.
* User: thomas
* Date: Jun 16, 2011
* Time: 4:41:19 PM
* To change this template use File | Settings | File Templates.
*/
public class CustomScript extends AbstractFloatSearchScript {
@Override
public float runAsFloat() {
int daysSinceRelease = doc().numeric("daysSinceRelease").getIntValue();
return (float) (0.4 * (-150.0 * pow(max(daysSinceRelease
- -30000.0, 0), 0.000001) * pow(max(-1826.0 - daysSinceRelease, 0), 0.000001) + -100.0 * pow(max(daysSinceRelease - -1825.0, 0), 0.000001) * pow(max(-1096.0 -
daysSinceRelease, 0), 0.000001) + (-100.0 + (daysSinceRelease - -1095.0) * (0.0 - -100.0) / (-548.0 - -1095.0)) * pow(max(daysSinceRelease - -1095.0, 0), 0.000001) * pow(max(-548.0 - daysSinceRelease, 0), 0.000001)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment