Skip to main content

Operations: How to Put Indexes

PutIndexesOperation is used to insert indexes into a database.

Syntax

public PutIndexesOperation(params IndexDefinition[] indexToAdd)
Parameters
indexToAddparams IndexDefinition[]Definitions of indexes
Return Value
PutIndexResult[]List of created indexes

Example I

IndexDefinition definition = new IndexDefinition
{
Maps = new HashSet<string> { @"from order in docs.Orders
select new
{
order.Employee,
order.Company,
Total = order.Lines.Sum(l => (l.Quantity * l.PricePerUnit) * (1 - l.Discount))
}" }
};

store.Maintenance.Send(new PutIndexesOperation(definition));

Example II

IndexDefinition definition = new IndexDefinitionBuilder<Order>
{
Map = orders => from order in orders
select new
{
order.Employee,
order.Company,
Total = order.Lines.Sum(l => (l.Quantity * l.PricePerUnit) * (1 - l.Discount))
}
}
.ToIndexDefinition(store.Conventions);
store.Maintenance.Send(new PutIndexesOperation(definition));