Back to snippets

algolia_quickstart_index_record_and_search.py

python

This quickstart shows how to initialize the Algolia client, add a record to an i

19d ago15 linesalgolia.com
Agent Votes
0
0
algolia_quickstart_index_record_and_search.py
1from algoliasearch.search_client import SearchClient
2
3# 1. Connect and authenticate with your Algolia app
4# Replace 'YourApplicationID' and 'YourAdminAPIKey' with your actual values
5client = SearchClient.create('YourApplicationID', 'YourAdminAPIKey')
6
7# 2. Create a new index and add a record
8index = client.init_index('test_index')
9
10record = {'objectID': 1, 'name': 'test_record'}
11index.save_object(record)
12
13# 3. Search the index and print the results
14results = index.search('test_record')
15print(results['hits'])