Reindex a specific repository for Code Search
プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。
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.
*Fisheye および Crucible は除く
Rebuilding the entire index:
If you are looking to reindex the entire instance, please see KB Rebuild the Search server indexes for Bitbucket Server
要約
Bitbucket code search does not return the expected results for a specific repository.
The considerations mentioned in the documentation Search for code in Bitbucket Server have been reviewed and the search results are considered incorrect.
例:
- a string that is expected to be found in a search is not returned
- a string that is not expected to be found in a search is returned
A reindex for the repo can be attempted.
If issues with search are widespread and observed in a lot of repos, please see Bitbucket Server Code Search is unable to find results from some or all repositories.
環境
This applies to Bitbucket Server version 6.0 and later.
原因
An error might have occurred at the time the repo is being indexed to the Search server (Elasticsearch or OpenSearch), such as when the instance ran low on disk space or if there were connectivity issues.
Note that indexing to the search server is only attempted up to 5 times. Even if the underlying root cause has been resolved, the indexing process will never try indexing a repo that has reached the maximum retry count again because the number of retries are stored in the index as well.
Before proceeding with the resolution described here, you will first need to ensure that the underlying problem that is causing indexing to fail is resolved. If you need help with this process, contact Atlassian Support via support.atlassian.com. Once the root cause has been found and the problem has been resolved, follow the resolution steps below to reindex a repo.
ソリューション
Step 1: Check the number of indexing retries
Check whether the number of indexing retries for the repo has already been reached or not by doing the following:
Get the repo id using the steps in Identifying a Repository on the Bitbucket Server
Then call the endpoint:
curl -u <SEARCH_USERNAME>:<SEARCH_PASSWORD> -X GET <SEARCH_SERVER_URL>/bitbucket-index-state/_doc/<REPO_ID>
ここで:
- SEARCH_USERNAME
- If you are using Elasticsearch, this is the
auth.basic.username
value in thebuckler.yml
file
If you are using the embedded Elasticsearch, thebuckler.yml
file is located in <BITBUCKET_HOME>/shared/search/bucker/buckler.yml
If you have a remote Elasticsearch instance, thebuckler.yml
file location would depend on how the remote Elasticsearch instance was configured. - If you are using OpenSearch, this is the user configured in the
internal_users.yml
file
See remote OpenSearch server - security configuration for more info
- If you are using Elasticsearch, this is the
- SEARCH_PASSWORD
- If you are using Elasticsearch, this is the
auth.basic.password
value in thebuckler.yml
file - If you are using OpenSearch, this is the password for the user configured in the
internal_users.yml
file
- If you are using Elasticsearch, this is the
- SEARCH_SERVER_URL is the URL for the search server instance
You can get this from the Bitbucket UI in:Administration > Server settings > Search > Search server URL
- REPO_ID is the repository id
This will output data on the repo's indexing state.
出力サンプル
{
"_index": "bitbucket-index-state",
"_type": "_doc",
"_id": "1",
"_version": 649,
"_seq_no": 6798,
"_primary_term": 302,
"found": true,
"_source": {
"public": false,
"fork": false,
"retries": 6,
"projectId": 1,
"indexedCommitId": "ec3deb7ae0280892f0689eb5582252c116626183"
}
}
Look for the "retries
" value in the output.
If the "retries
" value is 5 or less, you can proceed directly to Step 3: Reindex the repo.
If the "retries
" is above 5, you need to go through Step 2: Reset the indexing retries count if the maximum limit has been reached first.
Step 2: Reset the indexing retries count if the maximum limit has been reached
Reset the "retries
" count to 0 with the following procedures:
Copy the "_source"
data from Step 1 and change the "retries"
value to 0. For example:
{
"public": false,
"fork": false,
"retries": 0,
"projectId": 1,
"indexedCommitId": "ec3deb7ae0280892f0689eb5582252c116626183"
}
Pass this data as the JSON_DATA
value to the following PUT call:
curl -u <SEARCH_USERNAME>:<SEARCH_PASSWORD> -X PUT <SEARCH_SERVER_URL>/bitbucket-index-state/_doc/<REPO_ID> \
-H 'Content-Type: application/json' \
-d '<JSON_DATA>'
例:
curl -u es_admin:es_password -X PUT http://localhost:7992/bitbucket-index-state/_doc/1 \
-H 'Content-Type: application/json' \
-d '{
"public": false,
"fork": false,
"retries": 0,
"projectId": 1,
"indexedCommitId": "ec3deb7ae0280892f0689eb5582252c116626183"
}'
Step 3: Reindex the repo
Reindex the repo for code search by calling the REST endpoint:
curl -u <USERNAME> -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' <BITBUCKET_URL>/rest/indexing/latest/projects/<PROJECT_KEY>/repos/<REPO_SLUG>/sync
ここで:
- USERNAME is the username of a Bitbucket Server user with administrative privileges
- BITBUCKET_URL is the base URL for the instance
- PROJECT_KEY is the project key in uppercase
- REPO_SLUG is the repository slug in lowercase
Afterwards, test the search again.