@@ -108,15 +108,8 @@ func (c *connector) listener(ctx *replication.ListenerContext) {
108108
109109 fullTableName := c .getFullTableName (msg .TableNamespace , msg .TableName )
110110
111- tableName , exists := c .cfg .Elasticsearch .TableIndexMapping [fullTableName ]
112- if ! exists {
113- parentTableName := c .getParentTableName (fullTableName , msg .TableNamespace , msg .TableName )
114- if parentTableName != "" {
115- tableName = c .cfg .Elasticsearch .TableIndexMapping [parentTableName ]
116- }
117- }
118-
119- if ! c .isTableInMapping (tableName ) {
111+ indexName := c .resolveTableToIndexName (fullTableName , msg .TableNamespace , msg .TableName )
112+ if indexName == "" {
120113 if err := ctx .Ack (); err != nil {
121114 logger .Error ("ack" , "error" , err )
122115 }
@@ -136,29 +129,38 @@ func (c *connector) listener(ctx *replication.ListenerContext) {
136129 chunks := slices .ChunkWithSize [elasticsearch.Action ](actions , batchSizeLimit )
137130 lastChunkIndex := len (chunks ) - 1
138131 for idx , chunk := range chunks {
139- c .bulk .AddActions (ctx , msg .EventTime , chunk , fullTableName , idx == lastChunkIndex )
132+ c .bulk .AddActions (ctx , msg .EventTime , chunk , indexName , idx == lastChunkIndex )
140133 }
141134 } else {
142- c .bulk .AddActions (ctx , msg .EventTime , actions , tableName , true )
135+ c .bulk .AddActions (ctx , msg .EventTime , actions , indexName , true )
143136 }
144137}
145138
146- func (c * connector ) isTableInMapping (tableName string ) bool {
147- if len (c .cfg .Elasticsearch .TableIndexMapping ) == 0 {
148- return true
139+ func (c * connector ) resolveTableToIndexName (fullTableName , tableNamespace , tableName string ) string {
140+ tableIndexMapping := c .cfg .Elasticsearch .TableIndexMapping
141+ if len (tableIndexMapping ) == 0 {
142+ return fullTableName
149143 }
150144
151- if _ , exists := c . cfg . Elasticsearch . TableIndexMapping [ tableName ]; exists {
152- return true
145+ if indexName , exists := tableIndexMapping [ fullTableName ]; exists {
146+ return indexName
153147 }
154148
155- t , ok := timescaledb .HyperTables .Load (tableName )
156- if ok {
157- _ , exists := c .cfg .Elasticsearch .TableIndexMapping [t .(string )]
158- return exists
149+ parentTableName := c .getParentTableName (fullTableName , tableNamespace , tableName )
150+ if parentTableName != "" {
151+ if indexName , exists := tableIndexMapping [parentTableName ]; exists {
152+ return indexName
153+ }
159154 }
160155
161- return tableName != ""
156+ if t , ok := timescaledb .HyperTables .Load (fullTableName ); ok {
157+ parentName := t .(string )
158+ if indexName , exists := tableIndexMapping [parentName ]; exists {
159+ return indexName
160+ }
161+ }
162+
163+ return ""
162164}
163165
164166func (c * connector ) getParentTableName (fullTableName , tableNamespace , tableName string ) string {
0 commit comments