query #
Base method used to send queries to Kuzzle, following the API Documentation.
This is a low-level method, exposed to allow advanced SDK users to bypass high-level methods.
Arguments #
query(request, [options]);
Argument | Type | Description |
---|---|---|
request | object | API request |
options | object | Optional query options |
request #
All properties necessary for the Kuzzle API can be added in the request object. The following properties are the most common.
Property | Type | Description |
---|---|---|
controller | string | Controller name (mandatory) |
action | string | Action name (mandatory) |
body | object | Query body for this action |
index | string | Index name for this action |
collection | string | Collection name for this action |
_id | string | id for this action |
volatile | object | Additional information to send to Kuzzle |
options #
Additional query options
Property | Type (default) | Description |
---|---|---|
queuable | boolean ( true ) | Make this request queuable or not |
Resolves #
Resolve to the raw Kuzzle API response. See the API Documentation.
Usage #
const request = {
controller: 'document',
action: 'create',
index: 'nyc-open-data',
collection: 'yellow-taxi',
_id: 'my-custom-document-id',
refresh: 'wait_for', // Additional property allowed for this API action
body: {
trip_distance: 4.23,
passenger_count: 2
}
};
try {
const response = await kuzzle.query(request);
console.log(response);
/*
{ requestId: '49ffb6db-bdff-45b9-b3f6-00442f472393',
status: 200,
error: null,
controller: 'document',
action: 'create',
collection: 'yellow-taxi',
index: 'nyc-open-data',
volatile: { sdkVersion: '6.0.0-beta-2' },
room: '49ffb6db-bdff-45b9-b3f6-00442f472393',
result:
{ _index: 'nyc-open-data',
_type: 'yellow-taxi',
_id: 'my-custom-document-id',
_version: 1,
result: 'created',
_shards: { total: 2, successful: 1, failed: 0 },
created: true,
_source:
{ trip_distance: 4.23,
passenger_count: 2,
_kuzzle_info:
{ author: '-1',
createdAt: 1532529302225,
updatedAt: null,
updater: null,
active: true,
deletedAt: null } } } }
*/
console.log('Document created');
} catch (error) {
console.error(error);
}
Edit this page on Github(opens new window)