SDK
SDK Java v1.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.

This SDK has been deprecated because of stability issues. It is not advised to use it in a production environment.

search #

Searches documents.

There is a limit to how many documents can be returned by a single search query. That limit is by default set at 10000 documents, and you can't get over it even with the from and size pagination options.

When processing a large number of documents (i.e. more than 1000), it is advised to paginate the results using SearchResult.next rather than increasing the size parameter.

Arguments #

Copied to clipboard!
io.kuzzle.sdk.SearchResult search(
  String index,
  String collection,
  String body,
  io.kuzzle.sdk.QueryOptions options
)
io.kuzzle.sdk.SearchResult search(
  String index,
  String collection,
  String body
)

Argument Type Description
index
String
Index name
collection
String
Collection name
body
String
A JSON string containing the search query
options
io.kuzzle.sdk.QueryOptions
Query options

options #

Additional query options

Option Type
(default)
Description
queuable
boolean

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

(1)
Offset of the first document to fetch
size
int

(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)

Body properties #

Optional: #

An empty body matches all documents in the queried collection.

Return #

Returns a io.kuzzle.sdk.SearchResult object.

Exceptions #

Throws a io.kuzzle.sdk.KuzzleException if there is an error. See how to handle error.

Usage #

Copied to clipboard!
String suv = "{\"category\": \"suv\"}";
String limousine = "{\"category\": \"limousine\"}";
try {
  int i;
  for (i = 0; i < 5; i++) {
    kuzzle.getDocument().create("nyc-open-data", "yellow-taxi", "", suv);
  }
  for (i = 5; i < 15; i++) {
    kuzzle.getDocument().create("nyc-open-data", "yellow-taxi", "", limousine);
  }
  kuzzle.getIndex().refresh("nyc-open-data");
  SearchResult response = kuzzle.getDocument().search(
    "nyc-open-data",
    "yellow-taxi",
    "{\"query\":{\"match\": {\"category\": \"suv\"}}}"
  );
  System.out.println(String.format("Successfully retrieved %d documents", response.getTotal()));
} catch (KuzzleException e) {
  System.err.println(e.getMessage());
}