async def create_indexer():
    # create an index
    index_name = "hotels"
    fields = [
        SimpleField(name="hotelId", type=SearchFieldDataType.String, key=True),
        SimpleField(name="baseRate", type=SearchFieldDataType.Double)
    ]
    index = SearchIndex(name=index_name, fields=fields)
    ind_client = SearchIndexerClient(service_endpoint, AzureKeyCredential(key))
    async with ind_client:
        await ind_client.create_index(index)

    # [START create_indexer_async]
    # create a datasource
    container = SearchIndexerDataContainer(name='searchcontainer')
    data_source_connection = SearchIndexerDataSourceConnection(
        name="indexer-datasource",
        type="azureblob",
        connection_string=connection_string,
        container=container)
    async with ind_client:
        data_source = await ind_client.create_data_source_connection(
            data_source_connection)

    # create an indexer
    indexer = SearchIndexer(name="async-sample-indexer",
                            data_source_name="async-indexer-datasource",
                            target_index_name="indexer-hotels")
    async with indexers_client:
        result = await indexers_client.create_indexer(indexer)
    print("Create new Indexer - async-sample-indexer")
Example #2
0
    async def _prepare_indexer(self, endpoint, api_key, name="sample-indexer", ds_name="sample-datasource", id_name="hotels"):
        con_str = self.settings.AZURE_STORAGE_CONNECTION_STRING
        self.scrubber.register_name_pair(con_str, 'connection_string')
        container = SearchIndexerDataContainer(name='searchcontainer')
        data_source_connection = SearchIndexerDataSourceConnection(
            name=ds_name,
            type="azureblob",
            connection_string=con_str,
            container=container
        )
        ds_client = SearchIndexerClient(endpoint, AzureKeyCredential(api_key))
        ds = await ds_client.create_data_source_connection(data_source_connection)

        index_name = id_name
        fields = [
        {
          "name": "hotelId",
          "type": "Edm.String",
          "key": True,
          "searchable": False
        }]
        index = SearchIndex(name=index_name, fields=fields)
        ind_client = SearchIndexClient(endpoint, AzureKeyCredential(api_key))
        ind = await ind_client.create_index(index)
        return SearchIndexer(name=name, data_source_name=ds.name, target_index_name=ind.name)
Example #3
0
 def _create_data_source_connection(self, cs, name):
     container = SearchIndexerDataContainer(name='searchcontainer')
     data_source_connection = SearchIndexerDataSourceConnection(
         name=name,
         type="azureblob",
         connection_string=cs,
         container=container)
     return data_source_connection
Example #4
0
 def _create_datasource(self, name="sample-datasource"):
     container = SearchIndexerDataContainer(name='searchcontainer')
     data_source = SearchIndexerDataSourceConnection(
         name=name,
         type="azureblob",
         connection_string=CONNECTION_STRING,
         container=container)
     return data_source
 def test_datasource_with_empty_connection_string(self):
     container = SearchIndexerDataContainer(name='searchcontainer')
     data_source_connection = SearchIndexerDataSourceConnection(
         name="test",
         type="azureblob",
         connection_string="",
         container=container)
     packed_data_source_connection = pack_search_indexer_data_source(
         data_source_connection)
     assert packed_data_source_connection.credentials.connection_string == "<unchanged>"
Example #6
0
def _create_datasource():
    # Here we create a datasource. As mentioned in the description we have stored it in
    # "searchcontainer"
    ds_client = SearchIndexerClient(service_endpoint, AzureKeyCredential(key))
    container = SearchIndexerDataContainer(name='searchcontainer')
    data_source = ds_client.create_datasource(
        name="hotel-datasource",
        type="azureblob",
        connection_string=connection_string,
        container=container)
    return data_source
Example #7
0
async def create_data_source_connection():
    # [START create_data_source_connection_async]
    container = SearchIndexerDataContainer(name='searchcontainer')
    data_source = SearchIndexerDataSourceConnection(
        name="async-sample-data-source-connection",
        type="azureblob",
        connection_string=connection_string,
        container=container
    )
    result = await client.create_data_source_connection(data_source)
    print("Create new Data Source Connection - async-sample-data-source-connection")
Example #8
0
    def _prepare_indexer(self, client, index_client, storage_cs, name,
                         container_name):
        data_source_connection = SearchIndexerDataSourceConnection(
            name=f"{name}-ds",
            type="azureblob",
            connection_string=storage_cs,
            container=SearchIndexerDataContainer(name=container_name))
        ds = client.create_data_source_connection(data_source_connection)

        fields = [{
            "name": "hotelId",
            "type": "Edm.String",
            "key": True,
            "searchable": False
        }]
        index = SearchIndex(name=f"{name}-hotels", fields=fields)
        ind = index_client.create_index(index)
        return SearchIndexer(name=name,
                             data_source_name=ds.name,
                             target_index_name=ind.name)