# new Query(init)
Assemble an elastic query.
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
init |
Object |
Properties
|
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 |
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 |
Returns:
this
Example
new Query({}).append( { some query clause } )
# fields(fields)
Define which fields to return
Parameters:
Name | Type | Description |
---|---|---|
fields |
string | array |
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 |
Returns:
this
Example
new Query({}).from(20)
# size(size)
Define how many query results to return
Parameters:
Name | Type | Description |
---|---|---|
size |
number |
Returns:
this
Example
new Query({}).size(20)
# sort(sort)
Define result sorting
Parameters:
Name | Type | Description |
---|---|---|
sort |
string | array |
Returns:
this
Examples
new Query({}).sort('user')
new Query({}).sort(['user', '_score'])
# toJSON() → {json}
Get a JSON representation of this object
Returns:
- Type
- json
# toJson() → {json}
Get a JSON representation of this object
Returns:
- Type
- json