query

// Using callbacks (NodeJS or Web Browser)
kuzzle.query({controller: 'document', action: 'search'}, {match: { message: 'this is a test' }}, function (err, res) {
  // ...
});

// Using promises (NodeJS only)
kuzzle
  .queryPromise({controller: 'document', action: 'search'}, {match: { message: 'this is a test' }})
  .then(result => {

  });
QueryArgs args = new QueryArgs();
args.controller = "document";
args.action = "search";
kuzzle.query(args, new JSONObject(), 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' => 'document',
  'action' => 'search'
];

$query = [
  'filter' => [
    'equals' => ['field' => 'value']
  ]
];

try {
  $response = $kuzzle->query($queryArgs, $query);
  // var_dump($response['result']['hits']);
}
catch (ErrorException $e) {

}

Callback response:

{ "error": null,
  "result": {
    "_shards": {
      "failed": 0,
      "successful": 5,
      "total": 5
    },
    "_source": {},
    "action": "search",
    "collection": "foo",
    "controller": "document",
    "hits": {
      "hits": [],
      "max_score": 0,
      "total": 0
    },
    "requestId": "bf87b930-7c02-11e5-ab10-dfa9e9fd2e07",
    "timed_out": false,
    "took": 1
  }
}

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


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

ArgumentTypeDescription
queryArgsJSON objectQuery base arguments
queryJSON objectQuery to execute
optionsJSON objectOptional parameters
callbackfunctionOptional callback

queryArgs

queryArgs is a JSON object with the following properties:

OptionTypeDescriptionRequired?
controllerstringAPI Controller argumentrequired
actionstringAPI Controller actionrequired
indexstringIndex concerned by the actionoptional
collectionstringData collection concerned by the actionoptional

Options

OptionTypeDescriptionDefault
volatileJSON objectAdditional information passed to notifications to other usersnull
queuablebooleanMark this request as (not) queuabletrue

Return value

Returns the Kuzzle object to allow chaining.


Callback response

Resolves to a JSON object containing the raw Kuzzle response.