Created
January 19, 2021 23:40
-
-
Save maguec/a2318f9c8b49ebc85df322b3eaffd251 to your computer and use it in GitHub Desktop.
Load Data using the batch indexer example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| from redisearch import Client, TextField | |
| import csv | |
| client = Client('WPOI', | |
| host='localhost', | |
| password='', | |
| port=6379 | |
| ) | |
| indexer = client.batch_indexer(chunk_size=1000) | |
| client.create_index(( | |
| TextField('TELNUM'), | |
| TextField('HTTP'), | |
| )) | |
| phone_chars = ['(', ')', '-', ' '] | |
| with open('./wpoi.csv', encoding='utf-8') as csv_file: | |
| csv_reader = csv.reader(csv_file, delimiter=',') | |
| headers = next(csv_reader, None) | |
| for row in csv_reader: | |
| indexer.add_document( | |
| row[0], | |
| nosave = True, | |
| TELNUM = ''.join(i for i in row[27] if not i in phone_chars), | |
| HTTP = row[30], | |
| ) | |
| indexer.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment