SDK
SDK Javascript v7.x
2

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 #

Copied to clipboard!
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
timeout
number
Time (in ms) during which a request will still be waited to be resolved. Set it -1 if you want to wait indefinitely

timeout #

::: warn The timeout option can only be used to prevent the SDK from being frozen if Kuzzle take too long to resolve a request, this will not prevent the request from being executed and Kuzzle will still resolve it at some point.

Resolves #

Resolve to the raw Kuzzle API response. See the API Documentation.

Usage #

Copied to clipboard!
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: { sdkName: 'javascript@7.0.0' },
      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 } } } }
  */
  console.log('Document created');
} catch (error) {
  console.error(error);
}