|
| 1 | +--- |
| 2 | +title: How to schedule indexers - Azure Search |
| 3 | +description: Schedule Azure Search indexers to index content periodically or at specific times. |
| 4 | + |
| 5 | +ms.date: 05/31/2019 |
| 6 | +author: RobDixon22 |
| 7 | +manager: HeidiSteen |
| 8 | +ms.author: v-rodixo |
| 9 | +services: search |
| 10 | +ms.service: search |
| 11 | +ms.devlang: rest-api |
| 12 | +ms.topic: conceptual |
| 13 | +ms.custom: seodec2018 |
| 14 | +--- |
| 15 | + |
| 16 | +# How to schedule indexers for Azure Search |
| 17 | +An indexer normally runs once, immediately after it is created. You can run it again on demand using the portal, the REST API, or the .NET SDK. You can also configure an indexer to run periodically on a schedule. |
| 18 | + |
| 19 | +Some situations where indexer scheduling is useful: |
| 20 | + |
| 21 | +* Source data will change over time, and you want the Azure Search indexers to automatically process the changed data. |
| 22 | +* The index will be populated from multiple data sources and you want to make sure the indexers run at different times to reduce conflicts. |
| 23 | +* The source data is very large and you want to spread the indexer processing over time. For more information about indexing large volumes of data, see [How to index large data sets in Azure Search](search-howto-large-index.md). |
| 24 | + |
| 25 | +The scheduler is a built-in feature of Azure Search. You can't use an external scheduler to control search indexers. |
| 26 | + |
| 27 | +## Define schedule properties |
| 28 | + |
| 29 | +An indexer schedule has two properties: |
| 30 | +* **Interval**, which defines the amount of time in between scheduled indexer executions. The smallest interval allowed is 5 minutes, and the largest is 24 hours. |
| 31 | +* **Start Time (UTC)**, which indicates the first time at which the indexer should be run. |
| 32 | + |
| 33 | +You can specify a schedule when first creating the indexer, or by updating the indexer's properties later. Indexer schedules can be set using the [portal](#portal), the [REST API](#restApi), or the [.NET SDK](#dotNetSdk). |
| 34 | + |
| 35 | +Only one execution of an indexer can run at a time. If an indexer is already running when its next execution is scheduled, that execution is postponed until the next scheduled time. |
| 36 | + |
| 37 | +Let’s consider an example to make this more concrete. Suppose we configure an indexer schedule with an **Interval** of hourly and a **Start Time** of June 1, 2019 at 8:00:00 AM UTC. Here’s what could happen when an indexer run takes longer than an hour: |
| 38 | + |
| 39 | +* The first indexer execution starts at or around June 1, 2019 at 8:00 AM UTC. Assume this execution takes 20 minutes (or any time less than 1 hour). |
| 40 | +* The second execution starts at or around June 1, 2019 9:00 AM UTC. Suppose that this execution takes 70 minutes - more than an hour – and it will not complete until 10:10 AM UTC. |
| 41 | +* The third execution is scheduled to start at 10:00 AM UTC, but at that time the previous execution is still running. This scheduled execution is then skipped. The next execution of the indexer will not start until 11:00 AM UTC. |
| 42 | + |
| 43 | +<a name="portal"></a> |
| 44 | + |
| 45 | +## Define a schedule in the portal |
| 46 | + |
| 47 | +The Import Data wizard in the portal lets you define the schedule for an indexer at creation time. The default Schedule setting is **Hourly**, which means the indexer runs once after it is created, and runs again every hour afterwards. |
| 48 | + |
| 49 | +You can change the Schedule setting to **Once** if you don't want the indexer to run again automatically, or to **Daily** to run once per day. Set it to **Custom** if you want to specify a different interval or a specific future Start Time. |
| 50 | + |
| 51 | +When you set the schedule to **Custom**, fields appear to let you specify the **Interval** and the **Start Time (UTC)**. The shortest time interval allowed is 5 minutes, and the longest is 1440 minutes (24 hours). |
| 52 | + |
| 53 | +  |
| 54 | + |
| 55 | +After an indexer has been created, you can change the schedule settings using the indexer's Edit panel. The Schedule fields are the same as in the Import Data wizard. |
| 56 | + |
| 57 | +  |
| 58 | + |
| 59 | +<a name="restApi"></a> |
| 60 | + |
| 61 | +## Define a schedule using the REST API |
| 62 | + |
| 63 | +You can define the schedule for an indexer using the REST API. To do this, include the **schedule** property when creating or updating the indexer. The example below shows a PUT request to update an existing indexer: |
| 64 | + |
| 65 | + PUT https://myservice.search.windows.net/indexers/myindexer?api-version=2019-05-06 |
| 66 | + Content-Type: application/json |
| 67 | + api-key: admin-key |
| 68 | + |
| 69 | + { |
| 70 | + "dataSourceName" : "myazuresqldatasource", |
| 71 | + "targetIndexName" : "target index name", |
| 72 | + "schedule" : { "interval" : "PT10M", "startTime" : "2015-01-01T00:00:00Z" } |
| 73 | + } |
| 74 | + |
| 75 | +The **interval** parameter is required. The interval refers to the time between the start of two consecutive indexer executions. The smallest allowed interval is 5 minutes; the longest is one day. It must be formatted as an XSD "dayTimeDuration" value (a restricted subset of an [ISO 8601 duration](https://www.w3.org/TR/xmlschema11-2/#dayTimeDuration) value). The pattern for this is: `P(nD)(T(nH)(nM))`. Examples: `PT15M` for every 15 minutes, `PT2H` for every 2 hours. |
| 76 | + |
| 77 | +The optional **startTime** indicates when scheduled executions should begin. If it is omitted, the current UTC time is used. This time can be in the past, in which case the first execution is scheduled as if the indexer has been running continuously since the original **startTime**. |
| 78 | + |
| 79 | +You can also run an indexer on demand at any time using the Run Indexer call. For more information about running indexers and setting indexer schedules, see [Run Indexer](https://docs.microsoft.com/rest/api/searchservice/run-indexer), [Get Indexer](https://docs.microsoft.com/rest/api/searchservice/get-indexer), and [Update Indexer](https://docs.microsoft.com/rest/api/searchservice/update-indexer) in the REST API Reference. |
| 80 | + |
| 81 | +<a name="dotNetSdk"></a> |
| 82 | + |
| 83 | +## Define a schedule using the .NET SDK |
| 84 | + |
| 85 | +You can define the schedule for an indexer using the Azure Search .NET SDK. To do this, include the **schedule** property when creating or updating an Indexer. |
| 86 | + |
| 87 | +The following C# example creates an indexer, using a predefined data source and index, and sets its schedule to run once every day starting 30 minutes from now: |
| 88 | + |
| 89 | +``` |
| 90 | + Indexer indexer = new Indexer( |
| 91 | + name: "azure-sql-indexer", |
| 92 | + dataSourceName: dataSource.Name, |
| 93 | + targetIndexName: index.Name, |
| 94 | + schedule: new IndexingSchedule( |
| 95 | + TimeSpan.FromDays(1), |
| 96 | + new DateTimeOffset(DateTime.UtcNow.AddMinutes(30)) |
| 97 | + ) |
| 98 | + ); |
| 99 | + await searchService.Indexers.CreateOrUpdateAsync(indexer); |
| 100 | +``` |
| 101 | +If the **schedule** parameter is omitted, the indexer will only run once immediately after it is created. |
| 102 | + |
| 103 | +The **startTime** parameter can be set to a time in the past. In that case, the first execution is scheduled as if the indexer has been running continuously since the given **startTime**. |
| 104 | + |
| 105 | +The schedule is defined using the [IndexingSchedule](https://docs.microsoft.com/dotnet/api/microsoft.azure.search.models.indexingschedule?view=azure-dotnet) class. The **IndexingSchedule** constructor requires an **interval** parameter specified using a **TimeSpan** object. The smallest interval value allowed is 5 minutes, and the largest is 24 hours. The second **startTime** parameter, specified as a **DateTimeOffset** object, is optional. |
| 106 | + |
| 107 | +The .NET SDK lets you control indexer operations using the [SearchServiceClient](https://docs.microsoft.com/dotnet/api/microsoft.azure.search.searchserviceclient) class and its [Indexers](https://docs.microsoft.com/dotnet/api/microsoft.azure.search.searchserviceclient.indexers) property, which implements methods from the **IIndexersOperations** interface. |
| 108 | + |
| 109 | +You can run an indexer on demand at any time using one of the [Run](https://docs.microsoft.com/dotnet/api/microsoft.azure.search.indexersoperationsextensions.run), [RunAsync](https://docs.microsoft.com/dotnet/api/microsoft.azure.search.indexersoperationsextensions.runasync), or [RunWithHttpMessagesAsync](https://docs.microsoft.com/dotnet/api/microsoft.azure.search.iindexersoperations.runwithhttpmessagesasync) methods. |
| 110 | + |
| 111 | +For more information about creating, updating, and running indexers, see [IIindexersOperations](https://docs.microsoft.com/dotnet/api/microsoft.azure.search.iindexersoperations?view=azure-dotnet). |
0 commit comments