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.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
DOC_FIELD_NAME
special field name to sort by index orderstatic ParseField
MISSING
static java.lang.String
NAME
static ParseField
SORT_MODE
static ParseField
UNMAPPED_TYPE
-
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 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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description SortFieldAndFormat
build(QueryShardContext context)
Create a @linkSortFieldAndFormat
from this builder.boolean
equals(java.lang.Object other)
static FieldSortBuilder
fromXContent(XContentParser parser, java.lang.String fieldName)
java.lang.String
getFieldName()
Returns the document field this sort should be based on.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()
java.lang.Object
missing()
Returns the value used when a field is missing in a doc.FieldSortBuilder
missing(java.lang.Object missing)
Sets the value when a field is missing in a doc.FieldSortBuilder
rewrite(QueryRewriteContext ctx)
Rewrites this instance based on the provided context.FieldSortBuilder
setNestedFilter(QueryBuilder nestedFilter)
Deprecated.set nested sort withsetNestedSort(NestedSortBuilder)
and retrieve withgetNestedSort()
FieldSortBuilder
setNestedPath(java.lang.String nestedPath)
Deprecated.set nested sort withsetNestedSort(NestedSortBuilder)
and retrieve withgetNestedSort()
FieldSortBuilder
setNestedSort(NestedSortBuilder nestedSort)
Sets theNestedSortBuilder
to be used for fields that are inside a nested object.SortMode
sortMode()
Returns what values to pick in the case a document contains multiple values for the targeted sort field.FieldSortBuilder
sortMode(SortMode sortMode)
Defines what values to pick in the case a document contains multiple values for the targeted sort field.XContentBuilder
toXContent(XContentBuilder builder, ToXContent.Params params)
java.lang.String
unmappedType()
Returns the type to use in case the current field is not mapped in an index.FieldSortBuilder
unmappedType(java.lang.String type)
Set the type to use in case the current field is not mapped in an index.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
-
MISSING
public static final ParseField MISSING
-
SORT_MODE
public static final ParseField SORT_MODE
-
UNMAPPED_TYPE
public static final ParseField UNMAPPED_TYPE
-
DOC_FIELD_NAME
public static final java.lang.String DOC_FIELD_NAME
special field name to sort by index order- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FieldSortBuilder
public FieldSortBuilder(FieldSortBuilder template)
Copy constructor.
-
FieldSortBuilder
public FieldSortBuilder(java.lang.String fieldName)
Constructs a new sort based on a document field.- Parameters:
fieldName
- The field name.
-
FieldSortBuilder
public FieldSortBuilder(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
-
getFieldName
public java.lang.String getFieldName()
Returns the document field this sort should be based on.
-
missing
public FieldSortBuilder missing(java.lang.Object missing)
Sets the value when a field is missing in a doc. Can also be set to_last
or_first
to 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
public FieldSortBuilder unmappedType(java.lang.String type)
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 isnull
then 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
public FieldSortBuilder sortMode(SortMode 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
public SortMode sortMode()
Returns what values to pick in the case a document contains multiple values for the targeted sort field.
-
setNestedFilter
@Deprecated public FieldSortBuilder 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()
Returns the nested filter that the nested objects should match with in order to be taken into account for sorting.
-
setNestedPath
@Deprecated public FieldSortBuilder 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. 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
public NestedSortBuilder getNestedSort()
Returns theNestedSortBuilder
-
setNestedSort
public FieldSortBuilder 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 params) throws java.io.IOException
- Throws:
java.io.IOException
-
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<FieldSortBuilder>
- Throws:
java.io.IOException
-
equals
public boolean equals(java.lang.Object other)
- 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
-
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
public FieldSortBuilder 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
-
-