|
from elasticsearch import Elasticsearch, helpers |
|
import pandas as pd |
|
|
|
|
|
books_df = pd.read_csv('data/Books.csv', dtype={'Year-Of-Publication': 'str'}, low_memory=False) |
|
|
|
|
|
es = Elasticsearch("http://localhost:9202") |
|
|
|
|
|
index_name = 'books' |
|
if not es.indices.exists(index=index_name): |
|
es.indices.create(index=index_name) |
|
|
|
|
|
actions = [ |
|
{ |
|
"_index": index_name, |
|
"_id": row['ISBN'], |
|
"_source": { |
|
"Book-Title": row['Book-Title'], |
|
"Book-Author": row['Book-Author'], |
|
"Year-Of-Publication": row['Year-Of-Publication'], |
|
"Publisher": row['Publisher'], |
|
"Image-URL-S": row['Image-URL-S'], |
|
"Image-URL-M": row['Image-URL-M'], |
|
"Image-URL-L": row['Image-URL-L'] |
|
} |
|
} |
|
for _, row in books_df.iterrows() |
|
] |
|
|
|
|
|
helpers.bulk(es, actions) |