-
Notifications
You must be signed in to change notification settings - Fork 0
Opensearch Repository
samithiwat edited this page Feb 11, 2023
·
6 revisions
Opensearch repository is the interface repository for query the data from opensearch database.
Opensearch repository can be initialize by NewOpenSearchRepository method with the OpensearchDocumentAble entity
repo := gosdk.NewOpenSearchRepository[*portfolio.Portfolio](*Logger, *OpensearchClient)
name | description |
---|---|
Logger | the logger service |
Opensearch Client | the client of the opensearch for calling an API |
name | description | example |
---|---|---|
repo | the opensearch repository instance |
The field that use to search for autocomplete suggestion
type Suggestion struct {
Input []string `json:"input" mapstructure:"input"`
Weight int `json:"weight" mapstructure:"weight"`
}
name | description |
---|---|
input | name of the inputs that use as keyword for suggestion |
weight | the boots use for calculate the search score |
The type of struct that can use with OpensearchRepository
type OpenSearchDocumentAble interface {
ToDoc() any
GetID() string
}
This library provided the method to create an index for the documents
if err := repo.CreateIndex(indexName, indexJsonRaw); err != nil {
// handle error
}
name | description | example |
---|---|---|
indexName | the name of index that you want to create | my-index-1 |
indexJsonRaw | the json raw data in []byte
|
This library provided the method to insert a document
if err := repo.Insert(indexName, docId, docData); err != nil {
// handle error
}
name | description | example |
---|---|---|
indexName | the name of index that you want to insert document | my-index-1 |
docId | define id of the documentation | 1 |
docData | raw data in []byte
|
This library provided the method to insert the bulk of documents
if err := repo.InsertBulk(indexName, docDataList); err != nil {
// handle error
}
name | description | example |
---|---|---|
indexName | the name of index | my-index-1 |
docDataList | the slice of docData that match with the type that you define when initialize repository |
This library provided the method for searching documents in database
if err := repo.Search(indexName, *request, *result, *paginationMetadata); err != nil {
// handle error
}
name | description | example |
---|---|---|
indexName | the name of index | my-index-1 |
request | the search request for convert to JSON in format *map[string]interface{}
|
|
result | the *map[string]interface{} for search result |
|
paginationMetadata | the PaginationMetadata from Base Entity
|
This library provided the method for searching documents in database
if err := repo.Suggest(indexName, *request, *result); err != nil {
// handle error
}
name | description | example |
---|---|---|
indexName | the name of index | my-index-1 |
request | the suggest request for convert to JSON in format *map[string]interface{}
|
|
result | the *map[string]interface{} for suggest result |