mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-23 05:42:33 +09:00
Drops `github.com/olivere/elastic/v7` (unmaintained) and replaces it
with a small in-house wrapper that speaks the Elasticsearch REST API
directly via `net/http`. The subset used by Gitea (`_cluster/health`,
`_bulk`, `_doc`, `_delete_by_query`, `_refresh`, `_search`, `HEAD`/`PUT`
index) is stable across the targeted servers, so no client library is
needed.
**Targets tested**
- Elasticsearch 7, 8, 9
- OpenSearch 1, 2, 3
**Why not `go-elasticsearch`?**
The official client enforces an `X-Elastic-Product` server-identity
check that OpenSearch deliberately fails, which would force shipping a
transport shim to defeat it. Going direct over `net/http` removes that
fight along with several MB of transitive deps (`elastic-transport-go`,
`go.opentelemetry.io/otel{,/metric,/trace}`, `auto/sdk`, `easyjson`,
`intern`, `logr`, `stdr`).
Replaces: #30755
Fixes: https://github.com/go-gitea/gitea/issues/30752
---
This PR was written with the help of Claude Opus 4.7
---------
Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
35 lines
929 B
Go
35 lines
929 B
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package elasticsearch
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
)
|
|
|
|
// VersionedIndexName returns the full index name with version suffix.
|
|
func (i *Indexer) VersionedIndexName() string {
|
|
return versionedIndexName(i.indexName, i.version)
|
|
}
|
|
|
|
func versionedIndexName(indexName string, version int) string {
|
|
if version == 0 {
|
|
// Old index name without version
|
|
return indexName
|
|
}
|
|
return fmt.Sprintf("%s.v%d", indexName, version)
|
|
}
|
|
|
|
func (i *Indexer) checkOldIndexes(ctx context.Context) {
|
|
for v := range i.version {
|
|
indexName := versionedIndexName(i.indexName, v)
|
|
exists, err := i.indexExists(ctx, indexName)
|
|
if err == nil && exists {
|
|
log.Warn("Found older elasticsearch index named %q, Gitea will keep the old NOT DELETED. You can delete the old version after the upgrade succeed.", indexName)
|
|
}
|
|
}
|
|
}
|