Skip to content

Commit 835bb35

Browse files
authored
배포 v1.7.2
배포 v1.7.2
2 parents ddf1586 + ab2d4f1 commit 835bb35

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

ELK/app/services/elasticsearch_service.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -241,30 +241,13 @@ def search_logs_by_user(self, user_id: str) -> List[Dict]:
241241
}
242242
},
243243
"sort": [
244-
{"createAt": {"order": "asc"}},
245-
{"_id": {"order": "asc"}} # Tie-breaker for documents with the same timestamp
244+
{"createAt": {"order": "asc"}}
246245
],
247-
"size": 1000 # 한 번에 가져올 문서 수
246+
"size": 10000 # Elasticsearch의 기본 최대 결과창 크기(10000)로 설정
248247
}
249248

250-
all_logs = []
251-
252-
# 첫 페이지 검색
253249
response = self.es.search(index=self.log_index_name, body=query)
254-
hits = response['hits']['hits']
255-
all_logs.extend(hit['_source'] for hit in hits)
256-
257-
# 다음 페이지가 있는 동안 계속 반복
258-
while len(hits) > 0:
259-
# 마지막 문서의 정렬 값을 다음 검색의 시작점으로 사용
260-
last_sort_values = hits[-1]['sort']
261-
query['search_after'] = last_sort_values
262-
263-
response = self.es.search(index=self.log_index_name, body=query)
264-
hits = response['hits']['hits']
265-
all_logs.extend(hit['_source'] for hit in hits)
266-
267-
return all_logs
250+
return [hit['_source'] for hit in response['hits']['hits']]
268251

269252
except Exception as e:
270253
print(f"로그 검색 오류: {e}")

0 commit comments

Comments
 (0)