Skip to content
Snippets Groups Projects
Commit c88ad68f authored by Jan Semmelink's avatar Jan Semmelink
Browse files

Added Delete() operation to search document store

parent a4c71c05
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,7 @@ type DocumentStore interface { ...@@ -19,6 +19,7 @@ type DocumentStore interface {
Write(id string, data interface{}) error Write(id string, data interface{}) error
Search(query Query, limit int64) (ids []string, totalCount int, err error) Search(query Query, limit int64) (ids []string, totalCount int, err error)
Get(id string) (doc interface{}, err error) Get(id string) (doc interface{}, err error)
Delete(id string) error
} }
type documentStore struct { type documentStore struct {
...@@ -283,3 +284,30 @@ func (ds *documentStore) Get(id string) (doc interface{}, err error) { ...@@ -283,3 +284,30 @@ func (ds *documentStore) Get(id string) (doc interface{}, err error) {
} }
return source.Interface(), nil return source.Interface(), nil
} }
func (ds *documentStore) Delete(id string) (err error) {
if ds == nil {
return errors.Errorf("document store == nil")
}
del := opensearchapi.DeleteRequest{
Index: ds.name,
DocumentType: "_doc",
DocumentID: id,
}
delResponse, err := del.Do(context.Background(), ds.w.client)
if err != nil {
err = errors.Wrapf(err, "failed to del document")
return
}
switch delResponse.StatusCode {
case http.StatusOK:
case http.StatusNotFound:
case http.StatusNoContent:
default:
resBody, _ := ioutil.ReadAll(delResponse.Body)
err = errors.Errorf("Del failed with HTTP status %v: %s", delResponse.StatusCode, string(resBody))
return
}
return nil
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment