Package org.elasticsearch.script
Class SearchScript
- java.lang.Object
-
- org.elasticsearch.script.SearchScript
-
- All Implemented Interfaces:
ScorerAware
public abstract class SearchScript extends java.lang.Object implements ScorerAware
A generic script used for per document use cases. Using aSearchScriptworks as follows:- Construct a
SearchScript.FactoryusingScriptService.compile(Script, ScriptContext) - Construct a
SearchScript.LeafFactoryfor a an index usingSearchScript.Factory.newFactory(Map, SearchLookup) - Construct a
SearchScriptfor a Lucene segment usingSearchScript.LeafFactory.newInstance(LeafReaderContext) - Call
setDocument(int)to indicate which document in the segment the script should be run for next - Call one of the
runmethods:run(),runAsDouble(), orrunAsLong()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSearchScript.FactoryA factory to construct statefulSearchScriptfactories for a specific index.static interfaceSearchScript.LeafFactoryA factory to constructSearchScriptinstances.
-
Field Summary
Fields Modifier and Type Field Description static ScriptContext<SearchScript.Factory>AGGS_CONTEXTstatic ScriptContext<SearchScript.Factory>CONTEXTThe context used to compileSearchScriptfactories.static ScriptContext<SearchScript.Factory>SCRIPT_SORT_CONTEXT
-
Constructor Summary
Constructors Constructor Description SearchScript(java.util.Map<java.lang.String,java.lang.Object> params, SearchLookup lookup, org.apache.lucene.index.LeafReaderContext leafContext)
-
Method Summary
Modifier and Type Method Description LeafDocLookupgetDoc()The doc lookup for the Lucene segment this script was created for.protected LeafSearchLookupgetLeafLookup()The leaf lookup for the Lucene segment this script was created for.java.util.Map<java.lang.String,java.lang.Object>getParams()Return the parameters for this script.doublegetScore()Return the score of the current document.java.lang.Objectrun()abstract doublerunAsDouble()Return the result as a double.longrunAsLong()Return the result as a long.voidsetDocument(int docid)Set the current document to run the script on next.voidsetNextAggregationValue(java.lang.Object value)Sets per-document aggregation_value.voidsetNextVar(java.lang.String field, java.lang.Object value)voidsetScorer(org.apache.lucene.search.Scorer scorer)
-
-
-
Field Detail
-
CONTEXT
public static final ScriptContext<SearchScript.Factory> CONTEXT
The context used to compileSearchScriptfactories.
-
AGGS_CONTEXT
public static final ScriptContext<SearchScript.Factory> AGGS_CONTEXT
-
SCRIPT_SORT_CONTEXT
public static final ScriptContext<SearchScript.Factory> SCRIPT_SORT_CONTEXT
-
-
Constructor Detail
-
SearchScript
public SearchScript(java.util.Map<java.lang.String,java.lang.Object> params, SearchLookup lookup, org.apache.lucene.index.LeafReaderContext leafContext)
-
-
Method Detail
-
getParams
public java.util.Map<java.lang.String,java.lang.Object> getParams()
Return the parameters for this script.
-
getLeafLookup
protected final LeafSearchLookup getLeafLookup()
The leaf lookup for the Lucene segment this script was created for.
-
getDoc
public final LeafDocLookup getDoc()
The doc lookup for the Lucene segment this script was created for.
-
setDocument
public void setDocument(int docid)
Set the current document to run the script on next.
-
setScorer
public void setScorer(org.apache.lucene.search.Scorer scorer)
- Specified by:
setScorerin interfaceScorerAware
-
getScore
public double getScore()
Return the score of the current document.
-
setNextAggregationValue
public void setNextAggregationValue(java.lang.Object value)
Sets per-document aggregation_value.The default implementation just calls
setNextVar("_value", value)but some engines might want to handle this differently for better performance.- Parameters:
value- per-document value, typically a String, Long, or Double
-
setNextVar
public void setNextVar(java.lang.String field, java.lang.Object value)
-
runAsLong
public long runAsLong()
Return the result as a long. This is used by aggregation scripts over long fields.
-
run
public java.lang.Object run()
-
runAsDouble
public abstract double runAsDouble()
Return the result as a double. This is the main use case of search script, used for document scoring.
-
-