Skip to main content
This page documents an earlier version of the API client. For the latest version, see Search an index.
Required ACL: search The search query only allows for the retrieval of up to 1,000 hits. If you need to retrieve more than 1,000 hits, you can either use the browse method or increase the paginationLimitedTo parameter.

Examples

SearchIndex index = client.SearchIndex("contacts");

// Search for "query string" in the index "contacts"
var result = index.Search<Contact>(new Query("query string"));

// Perform the same search, but only retrieve 50 results
// Return only the attributes "firstname" and "lastname"
var result = index.Search<Contact>(new Query("query string")
{
  AttributesToRetrieve = new List<string> { "firstname", "lastname" }
  HitsPerPage = 50
});

// Search asynchronously
var result = await index.SearchAsync<Contact>(new Query("query string"));

Search and send an extra header

Index index = client.InitIndex("contacts");

RequestOptions requestOptions = new RequestOptions
{
    Headers = new Dictionary<string,string>{ { "X-Algolia-UserToken", "user123" } }
};

var result = index.Search<Contact>(new Query("query string"), requestOptions);

Parameters

query
string
required
The query used to search. Accepts every character, and every character entered will be used in the search. There’s a hard limit of 512 characters per query. If a search query is longer, the API will return an error.An empty query can be used to fetch all records.
requestOptions
object
A mapping of request options when using this method.
searchParameters
object
Search parameters to send with the query.

Response

abTestID
integer
If a search encounters an index that is being A/B tested, abTestID reports the ongoing A/B test ID.Returned only if getRankingInfo is set to true.
abTestVariantID
integer
If a search encounters an index that is being A/B tested, abTestVariantID reports the variant ID of the index used (note, this is the ID not the name). The variant ID is the position in the array of variants (starting at 1).For example, abTestVariantID=1 is variant A (the main index), abTestVariantID=2 is variant B (the replica you chose when creating the A/B test, or the queries with the changed query parameters if the A/B test is based on query parameters).Returned only if getRankingInfo is set to true.
aroundLatLng
string
The computed geo location. Warning: for legacy reasons, this parameter is a string and not an object. Format: ${lat},${lng}, where the latitude and longitude are expressed as decimal floating point numbers.Only returned when aroundLatLngViaIP or aroundLatLng is set.
automaticRadius
string
The automatically computed radius. For legacy reasons, this parameter is a string and not an integer.Only returned for geo queries without an explicitly specified radius (see aroundRadius).
exhaustive
object
Whether certain properties of the search response are calculated exhaustive (exact) or approximated.List of fields:
  • facetsCount: Whether the facet count is exhaustive (true) or approximate (false). See the related discussion.
  • facetValues: The value is false if not all facet values are retrieved.
  • nbHits: Whether the nbHits is exhaustive (true) or approximate (false).
  • When the query takes more than 50ms to be processed, the engine makes an approximation. This can happen when using complex filters on millions of records, when typo-tolerance was not exhaustive, or when enough hits have been retrieved (for example, after the engine finds 10,000 exact matches). nbHits is reported as non-exhaustive whenever an approximation is made, even if the approximation didn’t, in the end, impact the exhaustivity of the query.
  • rulesMatch: Rules matching exhaustivity. The value is false if rules were enable for this query, and could not be fully processed due a timeout. This is generally caused by the number of alternatives (such as typos) which is too large.
  • typo: Whether the typo search was exhaustive (true) or approximate (false). An approximation is done when the typo search query part takes more than 10% of the query budget (ie. 5ms by default) to be processed\n (this can happen when a lot of typo alternatives exist for the query).\n This field will not be included when typo-tolerance is entirely disabled.
exhaustiveFacetsCount
boolean
deprecated
See the facetsCount field of the exhaustive object in the response.
exhaustiveNbHits
boolean
deprecated
See the nbHits field of the exhaustive object in the response.
exhaustiveTypo
boolean
deprecated
See the typo field of the exhaustive object in the response.
facets
object
A mapping of each facet name to the corresponding facet counts.Returned only if facets is non-empty.
facets_stats
object
Statistics for numerical facets.${facet_name} (object): The statistics for a given facet:
  • min (number): The minimum value in the result set.
  • max (number): The maximum value in the result set.
  • avg (number): The average facet value in the result set.
  • sum (number): The sum of all values in the result set.
Regardless of the number of requested facet values (as per maxValuesPerFacet), statistics are always computed on at most 1,000 distinct values (starting with the most frequent ones). If there are more than 1,000 distinct values, statistics may therefore not be 100% accurate.Returned only if facets is non-empty and at least one of the returned facets contains numerical values.
hits
hit[]
The hits returned by the search.Hits are ordered according to the ranking or sorting of the index being queried.Hits are made of the schemaless JSON objects that you stored in the index.However, Algolia does enrich them with a few additional fields, such as _highlightResult, _snippetResult, _rankingInfo, and _distinctSeqID.Example:
JSON
hits: [
  {
    field1 : "",
    field2 : "",
    // [...],

    _highlightResult: {
      // [...]
    },
    _snippetResult: {
      // [...]
    },
    _rankingInfo: {
      // [...]
    },
    _distinctSeqID:
  },
  // [...]
]
hitsPerPage
integer
The maximum number of hits returned per page. See the hitsPerPage search parameter.Not returned if you use offset and length for pagination.
indexUsed
string
Index name used for the query. In the case of an A/B test, the targeted index isn’t always the index used by the query.Returned only if getRankingInfo is set to true.
message
string
Used to return warnings about the query.
nbHits
integer
The number of hits matched by the query.
nbPages
integer
The number of returned pages. Calculation is based on the total number of hits (nbHits) divided by the number of hits per page (hitsPerPage), rounded up to the nearest integer.Not returned if you use offset and length for pagination.
nbSortedHits
integer
The number of hits selected and sorted by the relevant sort algorithm.Only returned when searching on a virtual replica.
page
integer
Index of the current page (zero-based). See the page search parameter.Not returned if you use offset/length for pagination.
params
string
A url-encoded string of all search parameters.
parsedQuery
string
The query string that will be searched, after normalization. Normalization includes removing stop words (if removeStopWords is enabled), and transforming portions of the query string into phrase queries (see advancedSyntax).Returned only if getRankingInfo is set to true.
processingTimeMS
integer
Time the server took to process the search request, in milliseconds. This doesn’t include network time.
processingTimingsMS
object
List of processing steps and their times, in milliseconds. You can use this list to investigate performance issues.
This parameter is experimental. Fields may change without further notice and may be different for different Algolia servers. The list of steps is not exhaustive.
query
string
An echo of the query text. See the query search parameter.
queryAfterRemoval
string
A markup text indicating which parts of the original query have been removed in order to retrieve a non-empty result set.The removed parts are surrounded by <em> tags.Only returned when removeWordsIfNoResults is set to lastWords or firstWords.
queryID
string
Unique identifier of the search query, for sending events to the Insights API.Returned only if clickAnalytics is true.
serverTimeMS
integer
Time the server took to process the complete request, in milliseconds. This does not include network time.
serverUsed
string
Actual host name of the server that processed the request. The DNS supports automatic failover and load balancing, so this may differ from the host name used in the request.Returned only if getRankingInfo is set to true.
timeoutCounts
boolean
deprecated
Use the facetsCount field of the exhaustive object in the response.Returned only if getRankingInfo is set to true.
timeoutHits
boolean
deprecated
Please use exhaustiveHitsCount instead.Returned only if getRankingInfo is set to true.
userData
object[]
Array of userData objects.Only returned if at least one rule containing a custom userData consequence was applied.

Response as JSON

This section shows the JSON response returned by the API. Each API client wraps this response in language-specific objects, so the structure may vary. To view the response, use the getLogs method. Don’t rely on the order of properties—JSON objects don’t preserve key order.
JSON
{
  "hits": [
    {
      "firstname": "Jimmie",
      "lastname": "Barninger",
      "objectID": "433",
      "_highlightResult": {
        "firstname": {
          "value": "<em>Jimmie</em>",
          "matchLevel": "partial"
        },
        "lastname": {
          "value": "Barninger",
          "matchLevel": "none"
        },
        "company": {
          "value": "California <em>Paint</em> & Wlpaper Str",
          "matchLevel": "partial"
        }
      }
    }
  ],
  "page": 0,
  "nbHits": 1,
  "nbPages": 1,
  "hitsPerPage": 20,
  "processingTimeMS": 1,
  "query": "jimmie paint",
  "params": "query=jimmie+paint&attributesToRetrieve=firstname,lastname&hitsPerPage=50"
}
I