SDK
SDK Javascript v7.x
2

searchUsers #

Searches users.


searchUsers([query], [options]);

PropertyTypeDescription
query
object
Search query
options
object
Query options

query #

The search query to apply to users content, using ElasticSearch Query DSL or the Koncorde Filters DSL syntax.

Available since 7.4.8

This method also supports the Koncorde Filters DSL to match documents by passing the lang argument with the value koncorde.
Koncorde filters will be translated into an Elasticsearch query.

Koncorde bool operator and regexp clause are not supported for search queries.

If left empty, the result will return all available users.

options #

PropertyType
(default)
Description
queuable
boolean

(true)
If true, queues the request during downtime, until connected to Kuzzle again
from
number

(0)
Offset of the first document to fetch
size
number

(10)
Maximum number of documents to retrieve per page
scroll
string

("")
When set, gets a forward-only cursor having its ttl set to the given value (ie 30s; cf elasticsearch time limits)
lang
string
Specify the query language to use. By default, it's elasticsearch but koncorde can also be used.
Available since 7.4.8
timeout
number

(-1)
Time (in ms) during which a request will still be waited to be resolved. Set it -1 if you want to wait indefinitely
triggerEvents
boolean

(false)
If set to true, will trigger events even if using Embeded SDK. You should always ensure that your events/pipes does not create an infinite loop.
Available since Kuzzle 2.31.0

Resolves #

A SearchResult object containing the retrieved User objects.

Usage #

With the ElasticSearch Query DSL syntax.

try {
  const results = await kuzzle.security.searchUsers({
    query: {
      term: {
        status: 'student'
      }
    }
  });
  console.log(results);
  /*
  UserSearchResult {
    aggregations: undefined,
    hits:
      [ User { _kuzzle: [Kuzzle], _id: 'user2', content: [Object] },
        User { _kuzzle: [Kuzzle], _id: 'user1', content: [Object] },
        User { _kuzzle: [Kuzzle], _id: 'user3', content: [Object] } ],
    fetched: 3,
    total: 3 }
   */
  console.log(`Successfully retrieved ${results.total} users`);
} catch (e) {
  console.error(e);
}

With the Koncorde Filters DSL syntax.

try {
  const results = await kuzzle.security.searchUsers({
    query: {
      equals: {
        status: 'student'
      }
    }
  }, { lang: 'koncorde' });
  console.log(results);
  /*
  UserSearchResult {
    aggregations: undefined,
    hits:
      [ User { _kuzzle: [Kuzzle], _id: 'user2', content: [Object] },
        User { _kuzzle: [Kuzzle], _id: 'user1', content: [Object] },
        User { _kuzzle: [Kuzzle], _id: 'user3', content: [Object] } ],
    fetched: 3,
    total: 3 }
   */
  console.log(`Successfully retrieved ${results.total} users`);
} catch (e) {
  console.error(e);
}