Package org.elasticsearch.search.sort
Class FieldSortBuilder
java.lang.Object
org.elasticsearch.search.sort.SortBuilder<FieldSortBuilder>
org.elasticsearch.search.sort.FieldSortBuilder
- All Implemented Interfaces:
NamedWriteable,Writeable,ToXContent,ToXContentObject,Rewriteable<SortBuilder<?>>
public class FieldSortBuilder extends SortBuilder<FieldSortBuilder>
A sort builder to sort based on a document field.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.ParamsNested 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.StringDOC_FIELD_NAMEspecial field name to sort by index orderstatic ParseFieldMISSINGstatic java.lang.StringNAMEstatic ParseFieldNUMERIC_TYPEstatic ParseFieldSORT_MODEstatic ParseFieldUNMAPPED_TYPEFields inherited from class org.elasticsearch.search.sort.SortBuilder
NESTED_FILTER_FIELD, NESTED_PATH_FIELD, order, ORDER_FIELD -
Constructor Summary
Constructors Constructor Description FieldSortBuilder(java.lang.String fieldName)Constructs a new sort based on a document field.FieldSortBuilder(StreamInput in)Read from a stream.FieldSortBuilder(FieldSortBuilder template)Copy constructor. -
Method Summary
Modifier and Type Method Description SortFieldAndFormatbuild(QueryShardContext context)Create a @linkSortFieldAndFormatfrom this builder.booleanequals(java.lang.Object other)static FieldSortBuilderfromXContent(XContentParser parser, java.lang.String fieldName)java.lang.StringgetFieldName()Returns the document field this sort should be based on.static MinAndMax<?>getMinMaxOrNull(QueryShardContext context, FieldSortBuilder sortBuilder)QueryBuildergetNestedFilter()Deprecated.set nested sort withsetNestedSort(NestedSortBuilder)and retrieve withgetNestedSort()java.lang.StringgetNestedPath()Deprecated.set nested sort withsetNestedSort(NestedSortBuilder)and retrieve withgetNestedSort()NestedSortBuildergetNestedSort()Returns theNestedSortBuilderjava.lang.StringgetNumericType()Returns the numeric type that values should translated to or null if the original numeric type should be preserved.static FieldSortBuildergetPrimaryFieldSortOrNull(SearchSourceBuilder source)Return theFieldSortBuilderif the primary sort in the providedsourceis an instance of this class, null otherwise.java.lang.StringgetWriteableName()Returns the name of the writeable objectinthashCode()static booleanhasPrimaryFieldSort(SearchSourceBuilder source)Return true if the primary sort in the providedsourceis an instance ofFieldSortBuilder.java.lang.Objectmissing()Returns the value used when a field is missing in a doc.FieldSortBuildermissing(java.lang.Object missing)Sets the value when a field is missing in a doc.FieldSortBuilderrewrite(QueryRewriteContext ctx)Rewrites this instance based on the provided context.FieldSortBuildersetNestedFilter(QueryBuilder nestedFilter)Deprecated.set nested sort withsetNestedSort(NestedSortBuilder)and retrieve withgetNestedSort()FieldSortBuildersetNestedPath(java.lang.String nestedPath)Deprecated.set nested sort withsetNestedSort(NestedSortBuilder)and retrieve withgetNestedSort()FieldSortBuildersetNestedSort(NestedSortBuilder nestedSort)Sets theNestedSortBuilderto be used for fields that are inside a nested object.FieldSortBuildersetNumericType(java.lang.String numericType)Forces the numeric type to use for the field.SortModesortMode()Returns what values to pick in the case a document contains multiple values for the targeted sort field.FieldSortBuildersortMode(SortMode sortMode)Defines what values to pick in the case a document contains multiple values for the targeted sort field.XContentBuildertoXContent(XContentBuilder builder, ToXContent.Params params)java.lang.StringunmappedType()Returns the type to use in case the current field is not mapped in an index.FieldSortBuilderunmappedType(java.lang.String type)Set the type to use in case the current field is not mapped in an index.voidwriteTo(StreamOutput out)Write this into the StreamOutput.Methods inherited from class org.elasticsearch.search.sort.SortBuilder
buildSort, fromXContent, order, order, parseNestedFilter, resolveNested, resolveNested, toString
-
Field Details
-
NAME
public static final java.lang.String NAME- See Also:
- Constant Field Values
-
MISSING
-
SORT_MODE
-
UNMAPPED_TYPE
-
NUMERIC_TYPE
-
DOC_FIELD_NAME
public static final java.lang.String DOC_FIELD_NAMEspecial field name to sort by index order- See Also:
- Constant Field Values
-
-
Constructor Details
-
FieldSortBuilder
Copy constructor. -
FieldSortBuilder
public FieldSortBuilder(java.lang.String fieldName)Constructs a new sort based on a document field.- Parameters:
fieldName- The field name.
-
FieldSortBuilder
Read from a stream.- Throws:
java.io.IOException
-
-
Method Details
-
writeTo
Description copied from interface:WriteableWrite this into the StreamOutput.- Throws:
java.io.IOException
-
getFieldName
public java.lang.String getFieldName()Returns the document field this sort should be based on. -
missing
Sets the value when a field is missing in a doc. Can also be set to_lastor_firstto sort missing last or first respectively. -
missing
public java.lang.Object missing()Returns the value used when a field is missing in a doc. -
unmappedType
Set the type to use in case the current field is not mapped in an index. Specifying a type tells Elasticsearch what type the sort values should have, which is important for cross-index search, if there are sort fields that exist on some indices only. If the unmapped type isnullthen query execution will fail if one or more indices don't have a mapping for the current field. -
unmappedType
public java.lang.String unmappedType()Returns the type to use in case the current field is not mapped in an index. -
sortMode
Defines what values to pick in the case a document contains multiple values for the targeted sort field. Possible values: min, max, sum and avgThe last two values are only applicable for number based fields.
-
sortMode
Returns what values to pick in the case a document contains multiple values for the targeted sort field. -
setNestedFilter
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.set nested sort withsetNestedSort(NestedSortBuilder)and retrieve withgetNestedSort()Returns the nested filter that the nested objects should match with in order to be taken into account for sorting. -
setNestedPath
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. By default when sorting on a field inside a nested object, the nearest upper nested object is selected as nested path. -
getNestedPath
@Deprecated public java.lang.String getNestedPath()Deprecated.set nested sort withsetNestedSort(NestedSortBuilder)and retrieve withgetNestedSort()Returns the nested path if sorting occurs in a field that is inside a nested object. -
getNestedSort
Returns theNestedSortBuilder -
setNestedSort
Sets theNestedSortBuilderto be used for fields that are inside a nested object. TheNestedSortBuildertakes a `path` argument and an optional nested filter that the nested objects should match with in order to be taken into account for sorting. -
getNumericType
public java.lang.String getNumericType()Returns the numeric type that values should translated to or null if the original numeric type should be preserved. -
setNumericType
Forces the numeric type to use for the field. The query will fail if this option is set on a field that is not mapped as a numeric in some indices. Specifying a numeric type tells Elasticsearch what type the sort values should have, which is important for cross-index search, if a field does not have the same type on all indices. Allowed values arelonganddouble. -
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException- Throws:
java.io.IOException
-
build
Description copied from class:SortBuilderCreate a @linkSortFieldAndFormatfrom this builder.- Specified by:
buildin classSortBuilder<FieldSortBuilder>- Throws:
java.io.IOException
-
hasPrimaryFieldSort
Return true if the primary sort in the providedsourceis an instance ofFieldSortBuilder. -
getPrimaryFieldSortOrNull
Return theFieldSortBuilderif the primary sort in the providedsourceis an instance of this class, null otherwise. -
getMinMaxOrNull
public static MinAndMax<?> getMinMaxOrNull(QueryShardContext context, FieldSortBuilder sortBuilder) throws java.io.IOExceptionReturn theMinAndMaxindexed value from the providedFieldSortBuilderornullif unknown. The value can be extracted on non-nested indexed mapped fields of type keyword, numeric or date, other fields and configurations returnnull.- Throws:
java.io.IOException
-
equals
public boolean equals(java.lang.Object other)- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
getWriteableName
public java.lang.String getWriteableName()Description copied from interface:NamedWriteableReturns the name of the writeable object -
fromXContent
public static FieldSortBuilder fromXContent(XContentParser parser, java.lang.String fieldName) throws java.io.IOException- Parameters:
parser- the input parser. The state on the parser contained in this context will be changed as a side effect of this method callfieldName- 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- Throws:
java.io.IOException
-
rewrite
Description copied from interface:RewriteableRewrites 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
-