How to find the latest indexed commit for a repository in Bitbucket Data Center

Still need help?

The Atlassian Community is here for you.

Ask the community


Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.

Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

When troubleshooting code search issues for a repository, it may be useful to find out the latest commit that has been indexed in the Search instance.

This article describes procedures for retrieving the latest commit that has been indexed.

Environment

  • Bitbucket Data Center
  • Applies to both bundled and external search instances

Solution

Step 1: Retrieve Repository ID

The repository id can be retrieved with the following methods;

  1. from the Bitbucket UI: go to Repository settings > Repository details and get the numeric value from the Location  field.
    Sample:
    If the Location  value is /var/application-data/bitbucket/shared/data/repositories/293 , the repository id is 293.

  2. from the database through the following query:
    select r.id as repo_id 
    from repository r
    inner join project p on r.project_id=p.id
    where p.project_key = '<PROJECT_KEY>' and r.slug='<REPO_SLUG>';
    where:
    PROJECT_KEY is the project key in uppercase
    REPO_SLUG is the repository slug in lowercase

Step 2: Query the Search instance with the above Repository ID

Query the Search instance’ bitbucket-index-state  index, passing the repository id value from the previous step.

 curl -k -u <SEARCH_USER>:<SEARCH_PASSWORD> 
'<SEARCH_INSTANCE_URL>/bitbucket-index-state/_doc/<REPO_ID>'

where:
SEARCH_USER - user used by Bitbucket to connect to the Search instance
SEARCH_PASSWORD - password
SEARCH_INSTANCE_URL - base URL for the search instance
REPO_ID - repository id retrieved from the previous step

Sample request:

 curl -k -u bitbucket:password
'https://opensearch:9200/bitbucket-index-state/_doc/293'

Sample output:

{
  "_index": "bitbucket-index-state",
  "_type": "_doc",
  "_id": "293",
  "_version": 34,
  "_seq_no": 2491,
  "_primary_term": 248,
  "found": true,
  "_source": {
    "archived": false,
    "public": false,
    "fork": false,
    "retries": 0,
    "projectId": 322,
    "indexedCommitId": "569ad3a183637661b1c0dead082dd30517f43183"
  }
}

From the response, the latest commit that has been indexed for repo id 293  is 569ad3a183637661b1c0dead082dd30517f43183

Additional Notes

  • Bitbucket only indexes the default branch

  • Please see other considerations for code search indexing in: Bitbucket search syntax
Last modified on Feb 16, 2025

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.