query

const 
  args = {
    controller: 'controller',
    action: 'action'
  },
  query = {
    body: {
      foo: 'bar'
    },
    other: 'argument'
  };

// Using callbacks (NodeJS or Web Browser)
kuzzle.query(args, query, function (err, res) {
  // ...
});

// Using promises (NodeJS only)
kuzzle
  .queryPromise(args, query)
  .then(result => {

  });
QueryArgs args = new QueryArgs();
args.controller = "controller";
args.action = "action";

JSONObject query = new JSONObject()
  .put("body", new JSONObject()
    .put("foo", "bar")
  )
  .put("other", "argument");

kuzzle.query(args, query, new OnQueryDoneListener() {
  @Override
  public void onSuccess(JSONObject object) {

  }

  @Override
  public void onError(JSONObject error) {
    // Handle error
  }
});
<?php
use \Kuzzle\Kuzzle;

$kuzzle = new Kuzzle('localhost');

$queryArgs = [
  'controller' => 'controller',
  'action' => 'action'
];

$query = [
  'body' => [
    'foo' => 'bar'
  ],
  'other' => 'argument'
];

try {
  $response = $kuzzle->query($queryArgs, $query);
}
catch (ErrorException $e) {

}

Callback response:

{ "error": null,
  "result": {
    "action": "action",
    "controller": "controller",
    "requestId": "bf87b930-7c02-11e5-ab10-dfa9e9fd2e07",
    "other properties": "depends of the query made"
  }
}

Base method used to send queries to Kuzzle, following the API Documentation.


query(queryArgs, query, [options], [callback])

Argument Type Description
queryArgs JSON object Query base arguments
query JSON object Query to execute
options JSON object Optional parameters
callback function Optional callback

queryArgs

queryArgs is a JSON object allowing Kuzzle to route your query to the right API method:

Option Type Description Required?
controller string API Controller argument required
action string API Controller action required
index string Index concerned by the action optional
collection string Data collection concerned by the action optional

query

query is a JSON object containing arguments specific to the query, such as a body property, a JWT hash, a document _id, or generic query options (such as from or size for search queries)


Options

Option Type Description Default
volatile JSON object Additional information passed to notifications to other users null
queuable boolean Make this request queuable or not true

Return Value

Returns the Kuzzle SDK object to allow chaining.


Callback Response

Returns a JSON object containing the raw Kuzzle response.