java.lang.Object
org.elasticsearch.search.sort.SortBuilder<FieldSortBuilder>
org.elasticsearch.search.sort.FieldSortBuilder
- All Implemented Interfaces:
NamedWriteable,VersionedNamedWriteable,Writeable,Rewriteable<SortBuilder<?>>,ToXContent,ToXContentObject
A sort builder to sort based on a document field.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.elasticsearch.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
FieldsModifier and TypeFieldDescriptionstatic final Stringspecial field name to sort by index orderstatic final ParseFieldstatic final ParseFieldstatic final Stringstatic final ParseFieldstatic final Stringspecial field name to sort by index orderstatic final ParseFieldstatic final ParseFieldFields inherited from class org.elasticsearch.search.sort.SortBuilder
NESTED_FILTER_FIELD, NESTED_PATH_FIELD, order, ORDER_FIELDFields inherited from interface org.elasticsearch.index.query.Rewriteable
MAX_REWRITE_ROUNDSFields inherited from interface org.elasticsearch.xcontent.ToXContent
EMPTY, EMPTY_PARAMS -
Constructor Summary
ConstructorsConstructorDescriptionFieldSortBuilder(String fieldName) Constructs a new sort based on a document field.Read from a stream.FieldSortBuilder(FieldSortBuilder template) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionbuild(SearchExecutionContext context) Create a SortFieldAndFormat from this builder.buildBucketedSort(SearchExecutionContext context, BigArrays bigArrays, int bucketSize, BucketedSort.ExtraData extra) Create a BucketedSort which is useful for sorting inside of aggregations.booleanbooleanstatic FieldSortBuilderfromXContent(XContentParser parser, String fieldName) Returns the document field this sort should be based on.Returns the external format that is specified viasetFormat(String)The minimal version of the recipient this object can be sent tostatic MinAndMax<?> getMinMaxOrNull(SearchExecutionContext context, FieldSortBuilder sortBuilder) Returns theNestedSortBuilderReturns the numeric type that values should translated to or null if the original numeric type should be preserved.static FieldSortBuilderReturn theFieldSortBuilderif the primary sort in the providedsourceis an instance of this class, null otherwise.Returns the name of the writeable objectinthashCode()static booleanReturn true if the primary sort in the providedsourceis an instance ofFieldSortBuilder.booleanisBottomSortShardDisjoint(SearchExecutionContext context, SearchSortValuesAndFormats bottomSortValues) Returns whether some values of the givenSearchExecutionContext.getIndexReader()are within the primary sort value provided in thebottomSortValues.missing()Returns the value used when a field is missing in a doc.Sets the value when a field is missing in a doc.Rewrites this instance based on the provided context.Specifies a format specification that will be used to format the output value of this sort field.setNestedSort(NestedSortBuilder nestedSort) Sets theNestedSortBuilderto be used for fields that are inside a nested object.setNumericType(String numericType) Forces the numeric type to use for the field.sortMode()Returns what values to pick in the case a document contains multiple values for the targeted sort field.Defines what values to pick in the case a document contains multiple values for the targeted sort field.booleantoXContent(XContentBuilder builder, ToXContent.Params params) Returns the type to use in case the current field is not mapped in an index.unmappedType(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, buildSort, fromXContent, order, order, parseNestedFilter, resolveNested, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.elasticsearch.xcontent.ToXContentObject
isFragment
-
Field Details
-
NAME
- See Also:
-
MISSING
-
SORT_MODE
-
UNMAPPED_TYPE
-
NUMERIC_TYPE
-
FORMAT
-
DOC_FIELD_NAME
special field name to sort by index order- See Also:
-
SHARD_DOC_FIELD_NAME
special field name to sort by index order- See Also:
-
-
Constructor Details
-
FieldSortBuilder
Copy constructor. -
FieldSortBuilder
Constructs a new sort based on a document field.- Parameters:
fieldName- The field name.
-
FieldSortBuilder
Read from a stream.- Throws:
IOException
-
-
Method Details
-
writeTo
Description copied from interface:WriteableWrite this into the StreamOutput.- Throws:
IOException
-
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
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
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. -
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
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 arelong,double,dateanddate_nanos. -
getFormat
Returns the external format that is specified viasetFormat(String) -
setFormat
Specifies a format specification that will be used to format the output value of this sort field. Currently, only "date" and "data_nanos" date types support this external format (i.e., date format). -
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException - Throws:
IOException
-
build
Description copied from class:SortBuilderCreate a SortFieldAndFormat from this builder.- Specified by:
buildin classSortBuilder<FieldSortBuilder>- Throws:
IOException
-
canRewriteToMatchNone
public boolean canRewriteToMatchNone() -
isBottomSortShardDisjoint
public boolean isBottomSortShardDisjoint(SearchExecutionContext context, SearchSortValuesAndFormats bottomSortValues) throws IOException Returns whether some values of the givenSearchExecutionContext.getIndexReader()are within the primary sort value provided in thebottomSortValues.- Throws:
IOException
-
buildBucketedSort
public BucketedSort buildBucketedSort(SearchExecutionContext context, BigArrays bigArrays, int bucketSize, BucketedSort.ExtraData extra) throws IOException Description copied from class:SortBuilderCreate a BucketedSort which is useful for sorting inside of aggregations.- Specified by:
buildBucketedSortin classSortBuilder<FieldSortBuilder>- Throws:
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(SearchExecutionContext context, FieldSortBuilder sortBuilder) throws IOException Return 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:
IOException
-
equals
-
hashCode
public int hashCode() -
getWriteableName
Description copied from interface:VersionedNamedWriteableReturns the name of the writeable object -
getMinimalSupportedVersion
Description copied from interface:VersionedNamedWriteableThe minimal version of the recipient this object can be sent to -
fromXContent
public static FieldSortBuilder fromXContent(XContentParser parser, String fieldName) throws 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:
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:
IOException
-
supportsParallelCollection
public boolean supportsParallelCollection()- Overrides:
supportsParallelCollectionin classSortBuilder<FieldSortBuilder>
-