Skip to content

Commit

Permalink
[KAN-87] 좌표 데이터 거리순 정렬을위해 geo_point로 변경 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkyoungdeok authored May 25, 2024
1 parent 144a577 commit 1cf5b28
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions csv-to-es.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"image_url": {"type": "text"},
"category": {"type": "text", "analyzer": "korean"},
"discount_content": {"type": "text", "analyzer": "korean"},
"longitude": {"type": "float"},
"latitude": {"type": "float"},
"location": {"type": "geo_point"},
"menus": {
"type": "nested",
"properties": {
Expand Down Expand Up @@ -88,18 +87,13 @@
else:
discount_content = None

if pd.notna(row['longitude']):
longitude = float(row['longitude'])
if pd.notna(row['longitude']) and pd.notna(row['latitude']):
location = {"lat": float(row['latitude']), "lon": float(row['longitude'])}
else:
longitude = None

if pd.notna(row['latitude']):
latitude = float(row['latitude'])
else:
latitude = None
location = None

print(row['name'], row['category'], row['review_count'], row['address'], rating, number, restaurant_image_url,
menus, longitude, latitude)
menus, location)
data = {
"id": row['id'],
"name": row['name'],
Expand All @@ -111,8 +105,7 @@
"image_url": restaurant_image_url,
"category": row['custom_category'],
"discount_content": discount_content,
"longitude": longitude,
"latitude": latitude,
"location": location,
"menus": menus,
}
if data.get("discount_content") is None:
Expand All @@ -125,6 +118,8 @@
data.pop("number")
if data.get("image_url") is None:
data.pop("image_url")
if data.get("location") is None:
data.pop("location")

response = es.index(index=index_name, id=row['id'], document=data)
print(f"Indexed document ID: {response['_id']}, Result: {response['result']}")
Expand Down

0 comments on commit 1cf5b28

Please sign in to comment.