Unknown SDK

SearchAsync

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!
public async Task<SearchResults> SearchAsync(
    string index, 
    string collection, 
    JObject query,
    SearchOptions options = null);

Argument Type Description
index
string
Index name
collection
string
Collection name
query
JObject
JObject representing the search query
options
SearchOptions
An instance of SearchOptions class

query

A JObject representing the query. Query can have the following root properties:

An empty body matches all documents in the queried collection.

Return

Returns a SearchResult instance.

Exceptions

Throws a KuzzleException if there is an error. See how to handle errors.

Usage

Copied to clipboard!
try {
  for (int i = 0; i < 5; i++) {
    await kuzzle.Document.CreateAsync(
      "nyc-open-data",
      "yellow-taxi",
      JObject.Parse(@"{
        ""category"": ""suv""
      }"));
  }
  for (int i = 5; i < 15; i++) {
    await kuzzle.Document.CreateAsync(
      "nyc-open-data",
      "yellow-taxi",
      JObject.Parse(@"{
        ""category"": ""limousine""
      }"));
  }
  await kuzzle.Index.RefreshAsync("nyc-open-data");
  SearchOptions options = new SearchOptions();
  options.From = 0;
  options.Size = 2;
  SearchResults result = await kuzzle.Document.SearchAsync(
    "nyc-open-data",
    "yellow-taxi",
    JObject.Parse(@"{
      ""query"": {
        ""match"": {
          ""category"": ""suv""
        }
      }
    }"),
    options);
  Console.WriteLine($"Successfully retrieved {result.Total} documents");
} catch (KuzzleException e) {
  Console.Error.WriteLine(e);
}