Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions platform/persistence/elastic.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/QuesmaOrg/quesma/platform/config"
"github.com/QuesmaOrg/quesma/platform/elasticsearch"
"github.com/QuesmaOrg/quesma/platform/logger"
"github.com/QuesmaOrg/quesma/platform/types"
"github.com/goccy/go-json"
"io"
"log"
Expand Down Expand Up @@ -60,20 +59,16 @@ func (p *ElasticJSONDatabase) refresh() error {

func (p *ElasticJSONDatabase) Put(key string, data string) error {

elasticsearchURL := fmt.Sprintf("%s/_update/%s", p.indexName, key)
elasticsearchURL := fmt.Sprintf("%s/_doc/%s", p.indexName, key)

w := Wrapper{Content: data}

updateContent := types.JSON{}
updateContent["doc"] = w
updateContent["doc_as_upsert"] = true

jsonData, err := json.Marshal(updateContent)
jsonData, err := json.Marshal(w)
if err != nil {
return err
}

resp, err := p.httpClient.Request(context.Background(), "POST", elasticsearchURL, jsonData)
resp, err := p.httpClient.Request(context.Background(), "PUT", elasticsearchURL, jsonData)
Copy link

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The response status is not checked after the request. Consider verifying resp.StatusCode for non-2xx values and returning an error for unexpected statuses to surface server-side failures.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's checked in line 77. Please review again.

if err != nil {
return err
}
Expand Down
Loading