27
27
28
28
from azure .core .credentials import AzureKeyCredential
29
29
from azure .search .documents .indexes .models import (
30
- SearchIndexerDataContainer , SearchIndex , SearchIndexer , SimpleField , SearchFieldDataType
30
+ SearchIndexerDataContainer ,
31
+ SearchIndexerDataSourceConnection ,
32
+ SearchIndex ,
33
+ SearchIndexer ,
34
+ SimpleField ,
35
+ SearchFieldDataType
31
36
)
32
37
from azure .search .documents .indexes .aio import SearchIndexerClient , SearchIndexClient
33
38
@@ -41,23 +46,28 @@ async def create_indexer():
41
46
SimpleField (name = "baseRate" , type = SearchFieldDataType .Double )
42
47
]
43
48
index = SearchIndex (name = index_name , fields = fields )
44
- ind_client = SearchIndexClient (service_endpoint , AzureKeyCredential (key ))
49
+ ind_client = SearchIndexerClient (service_endpoint , AzureKeyCredential (key ))
45
50
async with ind_client :
46
51
await ind_client .create_index (index )
47
52
48
53
# [START create_indexer_async]
49
54
# create a datasource
50
55
container = SearchIndexerDataContainer (name = 'searchcontainer' )
56
+ data_source_connection = SearchIndexerDataSourceConnection (
57
+ name = "indexer-datasource" ,
58
+ type = "azureblob" ,
59
+ connection_string = connection_string ,
60
+ container = container
61
+ )
51
62
async with ind_client :
52
- data_source = await ind_client .create_datasource (
53
- name = "async-indexer-datasource" ,
54
- type = "azureblob" ,
55
- connection_string = connection_string ,
56
- container = container
57
- )
63
+ data_source = await ind_client .create_data_source_connection (data_source_connection )
58
64
59
65
# create an indexer
60
- indexer = SearchIndexer (name = "async-sample-indexer" , data_source_name = "async-indexer-datasource" , target_index_name = "hotels" )
66
+ indexer = SearchIndexer (
67
+ name = "async-sample-indexer" ,
68
+ data_source_name = "async-indexer-datasource" ,
69
+ target_index_name = "indexer-hotels"
70
+ )
61
71
async with indexers_client :
62
72
result = await indexers_client .create_indexer (indexer )
63
73
print ("Create new Indexer - async-sample-indexer" )
0 commit comments