Package org.elasticsearch.search.sort
Class ScriptSortBuilder
- java.lang.Object
-
- org.elasticsearch.search.sort.SortBuilder<ScriptSortBuilder>
-
- org.elasticsearch.search.sort.ScriptSortBuilder
-
- All Implemented Interfaces:
NamedWriteable
,Writeable
,ToXContent
,ToXContentObject
,Rewriteable<SortBuilder<?>>
public class ScriptSortBuilder extends SortBuilder<ScriptSortBuilder>
Script sort builder allows to sort based on a custom script expression.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ScriptSortBuilder.ScriptSortType
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
NAME
static ParseField
SCRIPT_FIELD
static ParseField
SORTMODE_FIELD
static ParseField
TYPE_FIELD
-
Fields inherited from class org.elasticsearch.search.sort.SortBuilder
NESTED_FILTER_FIELD, NESTED_PATH_FIELD, order, ORDER_FIELD
-
Fields inherited from interface org.elasticsearch.index.query.Rewriteable
MAX_REWRITE_ROUNDS
-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Constructor Summary
Constructors Constructor Description ScriptSortBuilder(StreamInput in)
Read from a stream.ScriptSortBuilder(Script script, ScriptSortBuilder.ScriptSortType type)
Constructs a script sort builder with the given script.
-
Method Summary
Modifier and Type Method Description SortFieldAndFormat
build(QueryShardContext context)
Create a @linkSortFieldAndFormat
from this builder.boolean
equals(java.lang.Object object)
static ScriptSortBuilder
fromXContent(XContentParser parser, java.lang.String elementName)
QueryBuilder
getNestedFilter()
Deprecated.set nested sort withsetNestedSort(NestedSortBuilder)
and retrieve withgetNestedSort()
java.lang.String
getNestedPath()
Deprecated.set nested sort withsetNestedSort(NestedSortBuilder)
and retrieve withgetNestedSort()
NestedSortBuilder
getNestedSort()
Returns theNestedSortBuilder
java.lang.String
getWriteableName()
Returns the name of the writeable objectint
hashCode()
ScriptSortBuilder
rewrite(QueryRewriteContext ctx)
Rewrites this instance based on the provided context.Script
script()
Get the script used in this sort.ScriptSortBuilder
setNestedFilter(QueryBuilder nestedFilter)
Deprecated.set nested sort withsetNestedSort(NestedSortBuilder)
and retrieve withgetNestedSort()
ScriptSortBuilder
setNestedPath(java.lang.String nestedPath)
Deprecated.set nested sort withsetNestedSort(NestedSortBuilder)
and retrieve withgetNestedSort()
ScriptSortBuilder
setNestedSort(NestedSortBuilder nestedSort)
Sets theNestedSortBuilder
to be used for fields that are inside a nested object.SortMode
sortMode()
Get the sort mode.ScriptSortBuilder
sortMode(SortMode sortMode)
Defines which distance to use for sorting in the case a document contains multiple values.
ForScriptSortBuilder.ScriptSortType.STRING
, the set of possible values is restricted toSortMode.MIN
andSortMode.MAX
XContentBuilder
toXContent(XContentBuilder builder, ToXContent.Params builderParams)
ScriptSortBuilder.ScriptSortType
type()
Get the type used in this sort.void
writeTo(StreamOutput out)
Write this into the StreamOutput.-
Methods inherited from class org.elasticsearch.search.sort.SortBuilder
buildSort, fromXContent, order, order, parseNestedFilter, resolveNested, resolveNested, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
-
-
-
Field Detail
-
NAME
public static final java.lang.String NAME
- See Also:
- Constant Field Values
-
TYPE_FIELD
public static final ParseField TYPE_FIELD
-
SCRIPT_FIELD
public static final ParseField SCRIPT_FIELD
-
SORTMODE_FIELD
public static final ParseField SORTMODE_FIELD
-
-
Constructor Detail
-
ScriptSortBuilder
public ScriptSortBuilder(Script script, ScriptSortBuilder.ScriptSortType type)
Constructs a script sort builder with the given script.- Parameters:
script
- The script to use.type
- The type of the script, can be eitherScriptSortBuilder.ScriptSortType.STRING
orScriptSortBuilder.ScriptSortType.NUMBER
-
ScriptSortBuilder
public ScriptSortBuilder(StreamInput in) throws java.io.IOException
Read from a stream.- Throws:
java.io.IOException
-
-
Method Detail
-
writeTo
public void writeTo(StreamOutput out) throws java.io.IOException
Description copied from interface:Writeable
Write this into the StreamOutput.- Throws:
java.io.IOException
-
script
public Script script()
Get the script used in this sort.
-
type
public ScriptSortBuilder.ScriptSortType type()
Get the type used in this sort.
-
sortMode
public ScriptSortBuilder sortMode(SortMode sortMode)
Defines which distance to use for sorting in the case a document contains multiple values.
ForScriptSortBuilder.ScriptSortType.STRING
, the set of possible values is restricted toSortMode.MIN
andSortMode.MAX
-
sortMode
public SortMode sortMode()
Get the sort mode.
-
setNestedFilter
@Deprecated public ScriptSortBuilder setNestedFilter(QueryBuilder nestedFilter)
Deprecated.set nested sort withsetNestedSort(NestedSortBuilder)
and retrieve withgetNestedSort()
Sets the nested filter that the nested objects should match with in order to be taken into account for sorting.
-
getNestedFilter
@Deprecated public QueryBuilder getNestedFilter()
Deprecated.set nested sort withsetNestedSort(NestedSortBuilder)
and retrieve withgetNestedSort()
Gets the nested filter.
-
setNestedPath
@Deprecated public ScriptSortBuilder setNestedPath(java.lang.String nestedPath)
Deprecated.set nested sort withsetNestedSort(NestedSortBuilder)
and retrieve withgetNestedSort()
Sets the nested path if sorting occurs on a field that is inside a nested object. For sorting by script this needs to be specified.
-
getNestedPath
@Deprecated public java.lang.String getNestedPath()
Deprecated.set nested sort withsetNestedSort(NestedSortBuilder)
and retrieve withgetNestedSort()
Gets the nested path.
-
getNestedSort
public NestedSortBuilder getNestedSort()
Returns theNestedSortBuilder
-
setNestedSort
public ScriptSortBuilder setNestedSort(NestedSortBuilder nestedSort)
Sets theNestedSortBuilder
to be used for fields that are inside a nested object. TheNestedSortBuilder
takes a `path` argument and an optional nested filter that the nested objects should match with in order to be taken into account for sorting.
-
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params builderParams) throws java.io.IOException
- Throws:
java.io.IOException
-
fromXContent
public static ScriptSortBuilder fromXContent(XContentParser parser, java.lang.String elementName)
- Parameters:
parser
- the input parser. The state on the parser contained in this context will be changed as a side effect of this method callelementName
- in some sort syntax variations the field name precedes the xContent object that specifies further parameters, e.g. in '{ "foo": { "order" : "asc"} }'. When parsing the inner object, the field name can be passed in via this argument
-
build
public SortFieldAndFormat build(QueryShardContext context) throws java.io.IOException
Description copied from class:SortBuilder
Create a @linkSortFieldAndFormat
from this builder.- Specified by:
build
in classSortBuilder<ScriptSortBuilder>
- Throws:
java.io.IOException
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
getWriteableName
public java.lang.String getWriteableName()
Description copied from interface:NamedWriteable
Returns the name of the writeable object
-
rewrite
public ScriptSortBuilder rewrite(QueryRewriteContext ctx) throws java.io.IOException
Description copied from interface:Rewriteable
Rewrites this instance based on the provided context. The returned objects will be the same instance as this if no changes during the rewrite were applied.- Throws:
java.io.IOException
-
-