Find Object
Required API Key:
any key with the
search
ACL
You’re currently reading the JavaScript API client v4 documentation. Check the migration guide to learn how to upgrade from v3 to v4. You can still access the v3 documentation.
You’re currently reading the Ruby API client v2 documentation. Check the migration guide to learn how to upgrade from v1 to v2. You can still access the v1 documentation.
About this method
Find an object by the given condition. Can be used to debug relevance.
findObject
may be used to debug the relevance of a specific object. This method
accepts a condition and returns the first matching object along with its position
information in the result set.
The findObject
method uses search internally so it can also retrieve the position for a given query.
For simply retrieving an object, you can use the more efficient getObjects
method instead.
Examples
Read the Algolia CLI documentation for more information.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$index->findObject(function($obj) {
return array_key_exists('firstname', $obj) && 'Jimmie' === $obj['firstname'];
});
// With a query
$options1 = [ 'query' => 'query string' ];
$index->findObject(function($obj) {
return array_key_exists('firstname', $obj) && 'Jimmie' === $obj['firstname'];
}, $options1);
// With a query and only the first page
$options2 = [ 'query' => 'query string', 'paginate' => false ];
$index->findObject(function($obj) {
return array_key_exists('firstname', $obj) && 'Jimmie' === $obj['firstname'];
}, $options2);
Parameters
callback
|
type: function
Required
The callback used to find the object. |
query
|
type: string
default: empty string
Optional
The query used to search. |
paginate
|
type: boolean
default: true
Optional
Whether to paginate the search results. |
requestOptions
|
type: key/value mapping
default: No request options
Optional
A mapping of request options, when using this method. |
index
|
type: string
Required
Only for Scala - The name of the index to query. |
Response
This section shows the JSON response returned by the API.
Each API client encapsulates this response inside objects specific to the programming language,
so that the actual response might be different.
You can view the response by using the getLogs
method.
Don’t rely on the order of attributes in the response, as JSON doesn’t guarantee the ordering of keys in objects.
JSON format
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"object": {
"firstname": "Jimmie",
"lastname": "Barninger",
"_highlightResult": {
"firstname": {
"value": "<em>Jimmie</em>",
"matchLevel": "partial"
},
"lastname": {
"value": "Barninger",
"matchLevel": "none"
},
"company": {
"value": "California <em>Paint</em> & Wlpaper Str",
"matchLevel": "partial"
}
}
},
"position": 0,
"page": 0
}
Field | Description |
---|---|
object
|
key/value mapping
The hit matching your callback. A hit is made of the schemaless JSON object that you stored in the index. However, Algolia enriches them with additional fields like object: { field1 : "", field2 : "", [...], _highlightResult: { [...] } } |
position
|
integer
Number of the matching object’s position in the result set (zero-based). |
page
|
integer
Number of the current page (zero-based). See the |