SDK
SDK Javascript v7.x
2

searchUsers #

Searches users.


Copied to clipboard!
searchUsers([query], [options]);

Property Type Description
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 #

Property Type
(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

Resolves #

A SearchResult object containing the retrieved User objects.

Usage #

With the ElasticSearch Query DSL syntax.

Copied to clipboard!
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.

Copied to clipboard!
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);
}