def test_upload_documents_new(self, api_key, endpoint, index_name, **kwargs): client = SearchClient(endpoint, index_name, AzureKeyCredential(api_key)) DOCUMENTS = [ { "hotelId": "1000", "rating": 5, "rooms": [], "hotelName": "Azure Inn" }, { "hotelId": "1001", "rating": 4, "rooms": [], "hotelName": "Redmond Hotel" }, ] results = client.upload_documents(DOCUMENTS) assert len(results) == 2 assert set(x.status_code for x in results) == {201} # There can be some lag before a document is searchable if self.is_live: time.sleep(TIME_TO_SLEEP) assert client.get_document_count() == 12 for doc in DOCUMENTS: result = client.get_document(key=doc["hotelId"]) assert result["hotelId"] == doc["hotelId"] assert result["hotelName"] == doc["hotelName"] assert result["rating"] == doc["rating"] assert result["rooms"] == doc["rooms"]
def test_upload_documents_existing(self, api_key, endpoint, index_name, **kwargs): client = SearchClient( endpoint, index_name, AzureKeyCredential(api_key) ) DOCUMENTS = [ {"hotelId": "1000", "rating": 5, "rooms": [], "hotelName": "Azure Inn"}, {"hotelId": "3", "rating": 4, "rooms": [], "hotelName": "Redmond Hotel"}, ] results = client.upload_documents(DOCUMENTS) assert len(results) == 2 assert set(x.status_code for x in results) == {200, 201}
def upload_docs(Data_Frame, index_name, endpoint, key): dataframe2 = list(Data_Frame.to_dict('records')) # Create a client credential = AzureKeyCredential(key) client = SearchClient(endpoint=endpoint, index_name=index_name, credential=credential) df = pd.read_csv('TrackerFiles/{}.csv'.format(index_name)) i = df.shape[0] + 1 for e in dataframe2: DOCUMENT = { 'Id': str(i), 'FileName': e['FileName'], 'FilePath': e['FilePath'], 'KeyPhrases': e['KeyPhrases'], 'People': e['people'], 'Organisation': e['org'], 'Location': e['loc'], } i += 1 result = client.upload_documents( documents=[DOCUMENT]) # documents = [document1,...,documentN]