ejsRequest

The Request object provides methods generating an elasticsearch request body.

Module

 Request

Request ( conf )

Provides methods for generating request bodies.


Parameters
conf <Object> A configuration object containing the initilization parameters. The following parameters can be set in the conf object: indices - single index name or array of index names types - single type name or array of types routing - the shard routing value

Properties

Name Description
query <Object> The internal query object.

Method Summary

Returns Name Description
String_type()The type of ejs object. For internal use only.
Objectagg(agg)Add an aggregation. This method can be called multiple times in order to set multiple nested aggregations that will be executed at the same time as the search request. Alias for the aggregation method.
Objectaggregation(agg)Add an aggregation. This method can be called multiple times in order to set multiple nested aggregations that will be executed at the same time as the search request.
Objectexplain(trueFalse)Enable/Disable explanation of score for each search result.
Objectfacet(facet)Allows you to set the specified facet on this request object. Multiple facets can be set, all of which will be returned when the search is executed.
Objectfields(s)By default, searches return full documents, meaning every property or field. This method allows you to specify which fields you want returned. Pass a single field name and it is appended to the current list of fields. Pass an array of fields and it replaces all existing fields.
Objectfilter(filter)Allows you to set a specified filter on this request object.
Objectfrom(f)A search result set could be very large (think Google). Setting the from parameter allows you to page through the result set by making multiple request. This parameters specifies the starting result/document number point. Combine with size() to achieve paging.
Objecthighlight(h)Performs highlighting based on the Highlight settings.
ObjectindexBoost(index,boost)Boosts hits in the specified index by the given boost value.
ObjectminScore(min)Filters out search results will scores less than the specified minimum score.
ObjectpartialField(oPartialField)Control what part of the _source will be loaded based on PartialField.
Objectpost_filter(filter)Allows you to set a specified post_filter on this request object.
Objectquery(someQuery)Allows you to set the specified query on this search object. This is the query that will be used when the search is executed.
Objectrescore(r)Once a query executes, you can use rescore to run a secondary, more expensive query to re-order the results.
ObjectscriptField(oScriptField)Computes a document property dynamically based on the supplied ScriptField.
Objectsize(s)Sets the number of results/documents to be returned. This is set on a per page basis.
Objectsort(fieldName)

Sets the sorting for the query. This accepts many input formats.

sort() - The current sorting values are returned.
sort(fieldName) - Adds the field to the current list of sorting values.
sort(fieldName, order) - Adds the field to the current list of sorting with the specified order. Order must be asc or desc.
sort(ejs.Sort) - Adds the Sort value to the current list of sorting values.
sort(array) - Replaces all current sorting values with values from the array. The array must contain only strings and Sort objects.

Multi-level sorting is supported so the order in which sort fields are added to the query requests is relevant.

It is recommended to use Sort objects when possible.

Objectsource(includes,excludes)Allows to control how the _source field is returned with every hit. By default operations return the contents of the _source field unless you have used the fields parameter or if the _source field is disabled. Set the includes parameter to false to completely disable returning the source field.
Objectsuggest(s)Allows you to set the specified suggester on this request object. Multiple suggesters can be set, all of which will be returned when the search is executed. Global suggestion text can be set by passing in a string vs. a Suggest object.
Objecttimeout(t)A timeout, bounding the request to be executed within the specified time value and bail when expired. Defaults to no timeout.

This option is valid during the following operations: search and delete by query

StringtoJSON()Retrieves the internal query object. This is typically used by internal API functions so use with caution.
ObjecttrackScores(trueFalse)Enables score computation and tracking during sorting. Be default, when sorting scores are not computed.
Objectversion(trueFalse)Enable/Disable returning version number for each search result.

Method Detail

 _type

String _type ( )
The type of ejs object. For internal use only.

Returns
the type of object

 agg

Object agg ( agg )
Add an aggregation. This method can be called multiple times in order to set multiple nested aggregations that will be executed at the same time as the search request. Alias for the aggregation method.

Parameters
agg <Aggregation> Any valid Aggregation object.
Returns
returns this so that calls can be chained.

 aggregation

Object aggregation ( agg )
Add an aggregation. This method can be called multiple times in order to set multiple nested aggregations that will be executed at the same time as the search request.

Parameters
agg <Aggregation> Any valid Aggregation object.
Returns
returns this so that calls can be chained.

 explain

Object explain ( trueFalse )
Enable/Disable explanation of score for each search result.

Parameters
trueFalse <Boolean> true to enable, false to disable
Returns
returns this so that calls can be chained.

 facet

Object facet ( facet )
Allows you to set the specified facet on this request object. Multiple facets can be set, all of which will be returned when the search is executed.

Parameters
facet <Facet> Any valid Facet object.
Returns
returns this so that calls can be chained.

 fields

Object fields ( s )
By default, searches return full documents, meaning every property or field. This method allows you to specify which fields you want returned. Pass a single field name and it is appended to the current list of fields. Pass an array of fields and it replaces all existing fields.

Parameters
s <String | String[]> The field as a string or fields as array
Returns
returns this so that calls can be chained.

 filter

Object filter ( filter )
Allows you to set a specified filter on this request object.

Parameters
filter <Object> Any valid Filter object.
Returns
returns this so that calls can be chained.

 from

Object from ( f )
A search result set could be very large (think Google). Setting the from parameter allows you to page through the result set by making multiple request. This parameters specifies the starting result/document number point. Combine with size() to achieve paging.

Parameters
f <Array> The offset at which to start fetching results/documents from the result set.
Returns
returns this so that calls can be chained.

 highlight

Object highlight ( h )
Performs highlighting based on the Highlight settings.

Parameters
h <Highlight> A valid Highlight object
Returns
returns this so that calls can be chained.

 indexBoost

Object indexBoost ( index, boost )
Boosts hits in the specified index by the given boost value.

Parameters
index <String> the index to boost
boost <Double> the boost value
Returns
returns this so that calls can be chained.

 minScore

Object minScore ( min )
Filters out search results will scores less than the specified minimum score.

Parameters
min <Double> a positive double value.
Returns
returns this so that calls can be chained.

 partialField

Object partialField ( oPartialField )
Control what part of the _source will be loaded based on PartialField.

Parameters
oPartialField <PartialField> A valid PartialField.
Returns
returns this so that calls can be chained.

 post_filter

Object post_filter ( filter )
Allows you to set a specified post_filter on this request object.

Parameters
filter <Object> Any valid Filter object.
Returns
returns this so that calls can be chained.

 query

Object query ( someQuery )
Allows you to set the specified query on this search object. This is the query that will be used when the search is executed.

Parameters
someQuery <Query> Any valid Query object.
Returns
returns this so that calls can be chained.

 rescore

Object rescore ( r )
Once a query executes, you can use rescore to run a secondary, more expensive query to re-order the results.

Parameters
r <Rescore> The rescore configuration.
Returns
returns this so that calls can be chained.

 scriptField

Object scriptField ( oScriptField )
Computes a document property dynamically based on the supplied ScriptField.

Parameters
oScriptField <ScriptField> A valid ScriptField.
Returns
returns this so that calls can be chained.

 size

Object size ( s )
Sets the number of results/documents to be returned. This is set on a per page basis.

Parameters
s <Integer> The number of results that are to be returned by the search.
Returns
returns this so that calls can be chained.

 sort

Object sort ( fieldName )

Sets the sorting for the query. This accepts many input formats.

sort() - The current sorting values are returned.
sort(fieldName) - Adds the field to the current list of sorting values.
sort(fieldName, order) - Adds the field to the current list of sorting with the specified order. Order must be asc or desc.
sort(ejs.Sort) - Adds the Sort value to the current list of sorting values.
sort(array) - Replaces all current sorting values with values from the array. The array must contain only strings and Sort objects.

Multi-level sorting is supported so the order in which sort fields are added to the query requests is relevant.

It is recommended to use Sort objects when possible.


Parameters
fieldName <String> The field to be sorted by.
Returns
returns this so that calls can be chained.

 source

Object source ( includes, excludes )
Allows to control how the _source field is returned with every hit. By default operations return the contents of the _source field unless you have used the fields parameter or if the _source field is disabled. Set the includes parameter to false to completely disable returning the source field.

Parameters
includes <String | Boolean | String[]> The field or list of fields to include as array. Set to a boolean false to disable the source completely.
excludes <String | String[]> The optional field or list of fields to exclude.
Returns
returns this so that calls can be chained.

 suggest

Object suggest ( s )
Allows you to set the specified suggester on this request object. Multiple suggesters can be set, all of which will be returned when the search is executed. Global suggestion text can be set by passing in a string vs. a Suggest object.

Since
elasticsearch 0.90
Parameters
s <String | Suggest> A valid Suggest object or a String to set as the global suggest text.
Returns
returns this so that calls can be chained.

 timeout

Object timeout ( t )
A timeout, bounding the request to be executed within the specified time value and bail when expired. Defaults to no timeout.

This option is valid during the following operations: search and delete by query


Parameters
t <Long> The timeout value in milliseconds.
Returns
returns this so that calls can be chained.

 toJSON

String toJSON ( )
Retrieves the internal query object. This is typically used by internal API functions so use with caution.

Returns
returns this object's internal object representation.

 trackScores

Object trackScores ( trueFalse )
Enables score computation and tracking during sorting. Be default, when sorting scores are not computed.

Parameters
trueFalse <Boolean> If scores should be computed and tracked.
Returns
returns this so that calls can be chained.

 version

Object version ( trueFalse )
Enable/Disable returning version number for each search result.

Parameters
trueFalse <Boolean> true to enable, false to disable
Returns
returns this so that calls can be chained.

Request

Queries

Filters

Aggregations

Facets

Suggesters

Geo