Query

Query~ Query

# new Query(init)

Assemble an elastic query.
Parameters:
Name Type Description
init Object
Properties
Name Type Description
size number the number of query results to return
from number where to return results from
Source:
Examples
new Query({})
new Query({ size: 20 })
new Query({ size: 20, from 123 })

Methods

# aggregation(query)

Append aggregations to this query
Parameters:
Name Type Description
query Object | array
Source:
Returns:
this
Example
new Query({}).aggregation( [ array of aggregation clauses ] )

# append(query)

Append a query clause to this query
Parameters:
Name Type Description
query Object
Source:
Returns:
this
Example
new Query({}).append( { some query clause } )

# fields(fields)

Define which fields to return
Parameters:
Name Type Description
fields string | array
Source:
Returns:
this
Examples
new Query({}).fields('user.id')
new Query({}).fields(['user.id', 'http.response.*'])

# from(from)

Define where to return results from (pagination)
Parameters:
Name Type Description
from number
Source:
Returns:
this
Example
new Query({}).from(20)

# size(size)

Define how many query results to return
Parameters:
Name Type Description
size number
Source:
Returns:
this
Example
new Query({}).size(20)

# sort(sort)

Define result sorting
Parameters:
Name Type Description
sort string | array
Source:
Returns:
this
Examples
new Query({}).sort('user')
new Query({}).sort(['user', '_score'])

# toJSON() → {json}

Get a JSON representation of this object
Source:
Returns:
Type
json

# toJson() → {json}

Get a JSON representation of this object
Source:
Returns:
Type
json