> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Find object

> Find an object by the given condition. Can be used to debug relevance.

**Required ACL:** `search`

Use this method to debug the relevance of a specific record.
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.
To retrieve an object, use the more efficient [`getObjects`](/doc/libraries/sdk/v1/methods/get-objects) method instead.

## Examples

<CodeGroup>
  ```cs C# theme={"system"}
  index.FindObject<Employee>(
    hit => hit.Firstname.Equals("Jimmie"),
    new Query());

  // With a query
  index.FindObject<Employee>(
    hit => hit.Firstname.Equals("Jimmie"),
    new Query("query string"));

  // With a query and only in the first page
  index.FindObject<Employee>(
    hit => hit.Firstname.Equals("Jimmie"),
    new Query("query string"),
    false);
  ```

  ```go Go theme={"system"}
  f := func(o map[string]interface{}) bool {
      itf, ok := o["firstname"]
      if !ok {
          return false
      }
      firstname, ok := itf.(string)
      return ok && firstname == "Jimmie"
  }

  index.FindObject(f, "", true)

  // With a query
  index.FindObject(f, "query string", true)

  // With a query and only in the first page
  index.FindObject(f, "query string", false)
  ```

  ```java Java theme={"system"}
  index.findObject(
      x -> x.getFirstName().equals("Jimmie"),
      new Query(""));

  // With a query
  index.findObject(
      x -> x.getFirstName().equals("Jimmie"),
      new Query("query string"));

  // With a query and only in the first page
  index.findObject(
      x -> x.getFirstName().equals("Jimmie"),
      new Query("query string"),
      false);
  ```

  ```js JavaScript theme={"system"}
  index.findObject(hit => hit.firstname == "Jimmie")
    .then(obj => {
      console.log(obj);
    });

  // With a query
  index.findObject(hit => hit.firstname == "Jimmie", {
    query: "query string"
  }).then(obj => {
    console.log(obj);
  });

  // With a query and only in the first page
  index.findObject(hit => hit.firstname == "Jimmie", {
    query: "query string",
    paginate: false
  }).then(obj => {
    console.log(obj);
  });
  ```

  ```kotlin Kotlin theme={"system"}
  val match: (ResponseSearch.Hit) -> Boolean = {
      it.json.getPrimitive("firstname").content == "Jimmie"
  }
  index.findObject(match)
  index.findObject(match, Query("query string"))
  index.findObject(match, Query("query string"), paginate = false)
  ```

  ```php PHP theme={"system"}
  $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);
  ```

  ```python Python theme={"system"}
  result = index.find_object(lambda hit: hit.get('firstname') == 'Jimmie')

  # With a query
  result = index.find_object(lambda hit: hit.get('firstname') == 'Jimmie', {
      'query': 'query string'
  })

  # With a query and only in the first page
  result = index.find_object(lambda hit: hit.get('firstname') == 'Jimmie', {
      'query': 'query string',
      'paginate': False
  })
  ```

  ```ruby Ruby theme={"system"}
  object = index.find_object(->(obj) { obj.key?('firstname') and obj['firstname'] == 'Jimmie' })

  # With a query
  object = index.find_object(->(obj) { obj.key?('firstname') and obj['firstname'] == 'Jimmie' }, {
    'query' => 'query string'
  })

  # With a query and only in the first page
  object = index.find_object(->(obj) { obj.key?('firstname') and obj['firstname'] == 'Jimmie' }, {
    'query' => 'query string',
    'paginate' => false
  })
  ```

  ```scala Scala theme={"system"}
  helper.findObject(
    indexName,
    Query(),
    (e: Employee) => e.firstName == "jimmie")

  // With a query
  helper.findObject(
    indexName,
    Query(query = Some("query string")),
    (e: Employee) => e.firstName == "jimmie"))

  // With a query and only in the first page
  helper.findObject(
    indexName,
    Query(query = Some("query string")),
    (e: Employee) => e.firstName == "jimmie",
    paginate = false)
  ```

  ```swift Swift theme={"system"}
  let predicate: (JSON) -> Bool = { hit in
    return hit["firstname"] == "Jimmie"
  }

  index.findObject(matching: predicate) { result in
    if case .success(let response) = result {
      print("Response: \(response)")
    }
  }

  // With a query
  index.findObject(matching: predicate, for: Query("query string")) { result in
    if case .success(let response) = result {
      print("Response: \(response)")
    }
  }

  // With a query and only in the first page
  index.findObject(matching: predicate,
                   for: Query("query string"),
                   paginate: false) { result in
    if case .success(let response) = result {
      print("Response: \(response)")
    }
  }
  ```
</CodeGroup>

## Parameters

<ParamField body="callback" type="function" required>
  The callback used to find the object.
</ParamField>

<ParamField body="index" type="string" required>
  **Scala only:** the name of the index to query.
</ParamField>

<ParamField body="paginate" type="boolean" default={true}>
  Whether to paginate the search results.
</ParamField>

<ParamField body="query" type="string">
  The query used to search.
</ParamField>

<ParamField body="requestOptions" type="object">
  A mapping of request options, when using this method.
</ParamField>

## Response

<ResponseField name="object" type="object">
  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 `_highlightResult`.

  **Example:**

  ```jsonc JSON icon=braces theme={"system"}
  object: {
      field1 : "",
      field2 : "",
      [...],

      _highlightResult: {
        [...]
      }
  }
  ```
</ResponseField>

<ResponseField name="page" type="integer">
  Number of the current page (zero-based). See the [`page`](/doc/api-reference/api-parameters/page) search parameter.
</ResponseField>

<ResponseField name="position" type="integer">
  Number of the matching object's position in the result set (zero-based).
</ResponseField>

### 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.

```jsonc JSON icon=braces theme={"system"}
{
  "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
}
```
