SDK
SDK PHP v3.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

searchUsers #

Return users matching the given filter.


searchUsers(filters, [options], callback) #

ArgumentsTypeDescription
filtersJSON ObjectFilter in Elasticsearch's Query DSL format
optionsJSON ObjectOptional parameters
callbackfunctionCallback handling the response

Options #

OptionTypeDescriptionDefault
fromnumberStarting offset0
queuablebooleanMake this request queuable or nottrue
scrollstringStart a scroll session, with a time to live equals to this parameter's value following the Elastisearch time formatundefined
sizenumberNumber of hits to return per result page10

To get more information about scroll sessions, please refer to the API reference documentation.


Callback Response #

Return a JSON Object

Usage #

<?php
use \Kuzzle\Kuzzle;
use \Kuzzle\Security\User;
use \Kuzzle\Util\UsersSearchResult;
$filters = [
  'bool' => [
    'must' => [
      [
        'terms' => [
          'profileIds' => ['anonymous', 'default'],
        ]
      ],
      [
        'geo_distance' => [
          'distance' => '10km',
          'pos' => [
            'lat' => 48.8566140,
            'lon' => 2.352222
          ]
        ]
      ]
    ]
  ]
];
// optional: result pagination configuration
$options = [
  'from' => 0,
  'size' => 1,
  'scroll' => '1m'
];
$kuzzle = new Kuzzle('localhost');
$security = $kuzzle->security();
try {
  $result = $security->searchUsers($filters, $options);
  // $result instanceof UsersSearchResult
  foreach($result->getUsers() as $user) {
    // $user instanceof User
  }
}
catch (ErrorException $e) {
}

Callback response:

{
  "total": 124,
  "users": [
    // array of User objects
  ],
  // only if a scroll parameter has been provided
  "scrollId": "<scroll identifier>"
}