Skip to content

Commit

Permalink
add multiple index support for elastic search document (#47)
Browse files Browse the repository at this point in the history
Signed-off-by: alihan.yalcin <alihan.yalcin@trendyol.com>
  • Loading branch information
alihanyalcin authored Dec 4, 2023
1 parent 7bf409f commit af04586
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
15 changes: 14 additions & 1 deletion elasticsearch/bulk/bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (b *Bulk) AddActions(
value := getEsActionJSON(
action.ID,
action.Type,
b.collectionIndexMapping[collectionName],
b.getIndexName(collectionName, action.IndexName),
action.Routing,
action.Source,
b.typeName,
Expand Down Expand Up @@ -313,3 +313,16 @@ func joinErrors(body map[string]any) error {
}
return fmt.Errorf(sb.String())
}

func (b *Bulk) getIndexName(collectionName, actionIndexName string) string {
if actionIndexName != "" {
return actionIndexName
}

indexName := b.collectionIndexMapping[collectionName]
if indexName == "" {
panic(fmt.Sprintf("there is no index mapping for collection: %s on your configuration", collectionName))
}

return indexName
}
9 changes: 5 additions & 4 deletions elasticsearch/document/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ const (
)

type ESActionDocument struct {
Routing *string
Type EsAction
Source []byte
ID []byte
Routing *string
Type EsAction
Source []byte
ID []byte
IndexName string
}

func NewDeleteAction(key []byte, routing *string) ESActionDocument {
Expand Down

0 comments on commit af04586

Please sign in to comment.