Add ETL Operation



Add RavenDB ETL task


The following example adds a RavenDB ETL task:

// Define the RavenDB ETL task configuration object
// ================================================
var ravenEtlConfig = new RavenEtlConfiguration
{
    Name = "task-name",
    ConnectionStringName = "raven-connection-string-name",
    Transforms =
    {
        new Transformation
        {
            // The script name
            Name = "script-name",
            
            // RavenDB collections the script uses
            Collections = { "Employees" },
            
            // The transformation script
            Script = @"loadToEmployees ({
                       Name: this.FirstName + ' ' + this.LastName,
                       Title: this.Title
                     });"
        }
    },

    // Do not prevent task failover to another node (optional) 
    PinToMentorNode = false
};

// Define the AddEtlOperation
// ==========================
var operation = new AddEtlOperation<RavenConnectionString>(ravenEtlConfig);

// Execute the operation by passing it to Maintenance.Send
// =======================================================
AddEtlOperationResult result = store.Maintenance.Send(operation);

Add SQL ETL task


The following example adds an SQL ETL task:

// Define the SQL ETL task configuration object
// ============================================
var sqlEtlConfig = new SqlEtlConfiguration
{
    Name = "task-name",
    ConnectionStringName = "sql-connection-string-name",
    SqlTables =
    {
        new SqlEtlTable {TableName = "Orders", DocumentIdColumn = "Id", InsertOnlyMode = false},
        new SqlEtlTable {TableName = "OrderLines", DocumentIdColumn = "OrderId", InsertOnlyMode = false},
    },
    Transforms =
    {
        new Transformation
        {
            Name = "script-name",
            Collections = { "Orders" },
            Script = @"var orderData = {
                                Id: id(this),
                                OrderLinesCount: this.Lines.length,
                                TotalCost: 0
                            };

                            for (var i = 0; i < this.Lines.length; i++) {
                                var line = this.Lines[i];
                                orderData.TotalCost += line.PricePerUnit;
                                
                                // Load to SQL table 'OrderLines'
                                loadToOrderLines({
                                    OrderId: id(this),
                                    Qty: line.Quantity,
                                    Product: line.Product,
                                    Cost: line.PricePerUnit
                                });
                            }
                            orderData.TotalCost = Math.round(orderData.TotalCost  * 100) / 100;

                            // Load to SQL table 'Orders'
                            loadToOrders(orderData)"
        }
    },

    // Do not prevent task failover to another node (optional) 
    PinToMentorNode = false
};

// Define the AddEtlOperation
// ===========================
var operation = new AddEtlOperation<SqlConnectionString>(sqlEtlConfig);

// Execute the operation by passing it to Maintenance.Send
// =======================================================
AddEtlOperationResult result = store.Maintenance.Send(operation);

Add OLAP ETL task


The following example adds an OLAP ETL task:

// Define the OLAP ETL task configuration object
// =============================================
var olapEtlConfig = new OlapEtlConfiguration
{
    Name = "task-name",
    ConnectionStringName = "olap-connection-string-name",
    Transforms =
    {
        new Transformation
        {
            Name = "script-name",
            Collections = {"Orders"},
            Script = @"var orderDate = new Date(this.OrderedAt);
                           var year = orderDate.getFullYear();
                           var month = orderDate.getMonth();
                           var key = new Date(year, month);
                           loadToOrders(key, {
                               Company : this.Company,
                               ShipVia : this.ShipVia
                           })"
        }
    }
};

// Define the AddEtlOperation
// ==========================
var operation = new AddEtlOperation<OlapConnectionString>(olapEtlConfig);

// Execute the operation by passing it to Maintenance.Send
// =======================================================
AddEtlOperationResult result = store.Maintenance.Send(operation);

Add Elasticsearch ETL task


The following example adds an Elasticsearch ETL task:

// Define the Elasticsearch ETL task configuration object
// ======================================================
var elasticsearchEtlConfig = new ElasticSearchEtlConfiguration
{
    Name = "task-name",
    ConnectionStringName = "elasticsearch-connection-string-name",
    ElasticIndexes =
    {
        // Define Elasticsearch Indexes
        new ElasticSearchIndex
        {
            // Elasticsearch Index name
            IndexName = "orders",
            // The Elasticsearch document property that will contain the source RavenDB document id.
            // Make sure this property is also defined inside the transform script.
            DocumentIdProperty = "DocId",
            InsertOnlyMode = false
        },
        new ElasticSearchIndex
        {
            IndexName = "lines",
            DocumentIdProperty = "OrderLinesCount",
            // If true, don't send _delete_by_query before appending docs
            InsertOnlyMode = true
        }
    },
    Transforms =
    {
        new Transformation()
        {
            Collections = { "Orders" },
            Script = @"var orderData = {
                       DocId: id(this),
                       OrderLinesCount: this.Lines.length,
                       TotalCost: 0
                       };

                       // Write the `orderData` as a document to the Elasticsearch 'orders' index
                       loadToOrders(orderData);",

            Name = "script-name"
        }
    }
};

// Define the AddEtlOperation
// ==========================
var operation = new AddEtlOperation<ElasticSearchConnectionString>(elasticsearchEtlConfig);

// Execute the operation by passing it to Maintenance.Send
// =======================================================
store.Maintenance.Send(operation);

Add Kafka ETL task


Add RabbitMQ ETL task


Add Azure Queue Storage ETL task


Syntax

public AddEtlOperation(EtlConfiguration<T> configuration)
Parameter Type Description
configuration EtlConfiguration<T> The ETL configuration object where T is the connection string type