def create_indexer(): # create an index index_name = "indexer-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 = SearchIndexClient(service_endpoint, AzureKeyCredential(key)) ind_client.create_index(index) # [START create_indexer] # create a datasource container = SearchIndexerDataContainer(name='searchcontainer') data_source = indexers_client.create_datasource( name="indexer-datasource", type="azureblob", connection_string=connection_string, container=container) # create an indexer indexer = SearchIndexer(name="sample-indexer", data_source_name="indexer-datasource", target_index_name="hotels") result = indexers_client.create_indexer(indexer) print("Create new Indexer - sample-indexer")
def test_delete_indexes_if_unchanged(self, api_key, endpoint, index_name, **kwargs): client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) # First create an index name = "hotels" fields = [{ "name": "hotelId", "type": "Edm.String", "key": True, "searchable": False }, { "name": "baseRate", "type": "Edm.Double" }] scoring_profile = ScoringProfile(name="MyProfile") scoring_profiles = [] scoring_profiles.append(scoring_profile) cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60) index = SearchIndex(name=name, fields=fields, scoring_profiles=scoring_profiles, cors_options=cors_options) result = client.create_index(index) etag = result.e_tag # get e tag and update index.scoring_profiles = [] client.create_or_update_index(index) index.e_tag = etag with pytest.raises(HttpResponseError): client.delete_index(index, match_condition=MatchConditions.IfNotModified)
def _create_index(): name = "hotel-index" # Here we create an index with listed fields. fields = [ SimpleField(name="hotelId", type=SearchFieldDataType.String, filterable=True, sortable=True, key=True), SearchableField(name="hotelName", type=SearchFieldDataType.String), SimpleField(name="description", type=SearchFieldDataType.String), SimpleField(name="descriptionFr", type=SearchFieldDataType.String), SimpleField(name="category", type=SearchFieldDataType.String), SimpleField(name="parkingIncluded", type=SearchFieldDataType.Boolean, filterable=True), SimpleField(name="smokingAllowed", type=SearchFieldDataType.Boolean, filterable=True), SimpleField(name="lastRenovationDate", type=SearchFieldDataType.String), SimpleField(name="rating", type=SearchFieldDataType.Int64, sortable=True), SimpleField(name="location", type=SearchFieldDataType.GeographyPoint), ] cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60) # pass in the name, fields and cors options and create the index index = SearchIndex(name=name, fields=fields, cors_options=cors_options) index_client = SearchIndexClient(service_endpoint, AzureKeyCredential(key)) result = index_client.create_index(index) return result
def create_index(name, endpoint, key): # Create a service client client = SearchIndexClient(endpoint, AzureKeyCredential(key)) fields = [ SimpleField(name='Id', type=SearchFieldDataType.String, key=True), SearchableField(name='FileName', type=SearchFieldDataType.String), SimpleField(name='FilePath', type=SearchFieldDataType.String), SearchableField(name='KeyPhrases', collection=True, type=SearchFieldDataType.String, analyzer_name="en.lucene"), SearchableField(name='People', collection=True, type=SearchFieldDataType.String), SearchableField(name='Organisation', collection=True, type=SearchFieldDataType.String), SearchableField(name='Location', collection=True, type=SearchFieldDataType.String) ] cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60) scoring_profiles = [] index = SearchIndex(name=name, fields=fields, scoring_profiles=scoring_profiles, cors_options=cors_options) result = client.create_index(index)
def test_create_index(self, api_key, endpoint, index_name, **kwargs): name = "hotels" fields = [ SimpleField(name="hotelId", type=edm.String, key=True), SimpleField(name="baseRate", type=edm.Double) ] scoring_profile = ScoringProfile(name="MyProfile") scoring_profiles = [] scoring_profiles.append(scoring_profile) cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60) index = SearchIndex(name=name, fields=fields, scoring_profiles=scoring_profiles, cors_options=cors_options) client = SearchIndexClient(endpoint, AzureKeyCredential(api_key)) result = client.create_index(index) assert result.name == "hotels" assert result.scoring_profiles[0].name == scoring_profile.name assert result.cors_options.allowed_origins == cors_options.allowed_origins assert result.cors_options.max_age_in_seconds == cors_options.max_age_in_seconds