Something went wrong. Try again.
My PaaS for hosting multiple elasticsearch clusters in a Kubernetes environment.
Something went wrong. Try again.
Docs Endpoints Implementation Plan #
Endpoints #
| Endpoint | Method | Path | Status | Response |
|---|---|---|---|---|
| IndexDoc | POST | /v1/search/{instanceId}/docs |
201 | DocumentIndexResponse |
| SearchDocs | GET | /v1/search/{instanceId}/docs |
200 | []Document |
| DeleteDoc | DELETE | /v1/search/{instanceId}/docs/{docId} |
204 | — |
Shared Helpers (add to server.go) #
defaultIndex(idx *string) string #
Returns "default" if idx is nil/empty, otherwise the dereferenced value.
readESBody(resp *esapi.Response) ([]byte, error) #
Reads and closes the ES response body, returns bytes. Prevents body leaks.
validateInstanceOwner(ctx context.Context, instanceId string, username string) error #
Fetches the ES cluster from K8s, checks:
- Instance exists → 404 if not
paas-instance-ownerlabel matchesusername→ 404 if not (consistent with existing pattern)
Returns error with appropriate message; callers map to HTTP status.
Endpoint Implementations #
IndexDoc #
- Parse body →
DocumentCreateRequest(viareqBody[T]) validateInstanceOwner→ 404 if not owner/missinggetESClient→ 500 if fails (instance not ready)- Resolve index via
defaultIndex(req.Index) - Build JSON body:
{"text": req.Text} - Call
esClient.Index(index, body, nil, ptr("wait_for"))— auto-generate doc ID,refresh=wait_forfor immediate searchability - Parse ES response JSON → extract
_idand_index - Return
201+DocumentIndexResponse{DocumentId, Index}
SearchDocs #
validateInstanceOwner→ 404getESClient→ 500- Resolve index via
defaultIndex(params.Index) - Build ES query:
{"query": {"match": {"text": params.Q}}} - Call
esClient.Search(index, body) - Parse hits →
[]api.Document:_id→DocumentId_source.text→Text_index→Index_score→Score(pointer, omit if zero)
- Return
200+ document array
DeleteDoc #
validateInstanceOwner→ 404getESClient→ 500- Call
esClient.Delete(params.Index, docId) - Check ES response status: if 404 → return
404"document not found" - Return
204No Content
Design Decisions #
| Decision | Choice | Rationale |
|---|---|---|
| Index default | "default" |
Matches OpenAPI spec default |
| Index mapping | ES dynamic mapping | Simplest — ES auto-creates index and maps text field |
| IndexDoc refresh | wait_for |
Document immediately searchable after indexing |
| SearchDocs query | match on text field |
Simple full-text search, sufficient for MVP |
| Ownership check | paas-instance-owner label |
Returns 404 for both not-found and not-owned (consistent with existing pattern) |
| Auth requirement | Owner-only | User must own the ES instance to operate on its docs |