REST API 2

[Elastic Search] MBTI ๊ฒ€์ƒ‰ ํ”„๋กœ์ ํŠธ - 3. API ๊ตฌ์ถ•ํ•˜๊ธฐ

MBTI ๊ฒ€์ƒ‰์—”์ง„ ๋ฐ์ดํ„ฐ๋ฅผ API ํ˜•ํƒœ๋กœ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค. API ๋ชฉ๋ก ์ „์ฒด ๋ฌธ์„œ์—์„œ ๊ฐ MBTI ํƒ€์ž…๋ณ„ ์ƒ์œ„ 100๊ฐœ ํ‚ค์›Œ๋“œ ์ถœ๋ ฅ - ๋ฌธ์„œ ์ˆ˜ ๊ธฐ์ค€ MBTI ์œ ํ˜• ์ค‘ E ๋˜๋Š” I ์œ ํ˜•์— ๋”ฐ๋ผ ์ƒ์œ„ 100๊ฐœ ํ‚ค์›Œ๋“œ ์ถœ๋ ฅ MBTI ์œ ํ˜• ์ค‘ E ๋˜๋Š” I ์œ ํ˜•์— ๋”ฐ๋ผ ๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ๊ฒ€์ƒ‰๋œ ์ƒ์œ„ 100๊ฐœ ํ‚ค์›Œ๋“œ ์ถœ๋ ฅ ๊ตฌํ˜„ํ•œ API๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ „์ฒด ๋ฌธ์„œ์—์„œ ๊ฐ MBTI ํƒ€์ž…๋ณ„ ์ƒ์œ„ 100๊ฐœ ํ‚ค์›Œ๋“œ๋ฅผ ์ถœ๋ ฅ @app.get('/top/keywords/{mbti_type}') def get_top_keywords(mbti_type: str, q:Optional[str]=None): es_query = { "size": 0, "query": {"match": {"keyword": mbti_type}}, "aggs..

Elastic Search 2022.04.29

[Elastic Search] ๊ฒ€์ƒ‰ ๊ตฌํ˜„ํ•˜๊ธฐ(with Fast API)

ES๋กœ ๊ฒ€์ƒ‰์—”์ง„์„ ๊ตฌํ˜„ํ•˜์˜€๋‹ค. ๊ตฌํ˜„๋œ ๊ฒ€์ƒ‰ ์—”์ง„์„ ์‹ค์ œ ์„œ๋น„์Šค์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด REST API๋ฅผ ๊ตฌํ˜„ํ•ด๋ณด์ž. REST API์˜ ๋กœ์ง์€ ๋‹จ์ˆœํ•˜๊ฒŒ ๋ณธ๋‹ค๋ฉด 2๋‹จ๊ณ„์ด๋‹ค. 1. ์‚ฌ์šฉ์ž๊ฐ€ ๊ฒ€์ƒ‰ ํ‚ค์›Œ๋“œ๋ฅผ ์ž…๋ ฅํ•œ๋‹ค. 2. ๊ฒ€์ƒ‰ ํ‚ค์›Œ๋“œ์— ํ•ด๋‹นํ•˜๋Š” ๋ฌธ์„œ๋ฅผ ์ฐพ๋Š”๋‹ค. ์‚ฌ์šฉ์ž ์ž…๋ ฅ ๊ตฌํ˜„ ์‚ฌ์šฉ์ž ์ž…๋ ฅ ๊ตฌํ˜„์—์„œ ๊ณ ๋ คํ•  ์ ์€ ๋‹จ์ˆœํ•˜๊ฒŒ ํ•˜๋‚˜์˜ ํ‚ค์›Œ๋“œ๋งŒ ์ž…๋ ฅ๋ฐ›์•„์„œ ๋ฌธ์„œ๋ฅผ ์ƒ์„ธํ•˜๊ฒŒ ๊ฒ€์ƒ‰ํ•  ์ˆ˜๋Š” ์—†๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ์œ ์‚ฌ์–ด, ์ œ์™ธ์–ด, ์—ฌ๋Ÿฌ ํ‚ค์›Œ๋“œ, And ์กฐ๊ฑด, Or ์กฐ๊ฑด ๋“ฑ ๋‹ค์–‘ํ•œ ์กฐ๊ฑด์œผ๋กœ ๊ฒ€์ƒ‰์ด ๊ฐ€๋Šฅํ•˜๋ฉด ์‚ฌ์šฉ์ž์—๊ฒŒ ๋” ์ข‹์€ ๊ฒ€์ƒ‰ ์‹œ์Šคํ…œ์ด ๋  ์ˆ˜ ์žˆ๋‹ค. ๊ทธ๋ž˜์„œ ๊ฒ€์ƒ‰ ํ‚ค์›Œ๋“œ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํŠน์ˆ˜ ์ปค๋งจ๋“œ๋ฅผ ์ •๋ฆฌํ•ด๋ณด์•˜๋‹ค. ๋‹จ์ผ ๊ฒ€์ƒ‰: search= ์˜ˆ) ๋งจํˆฌ๋งจ ์œ ์‚ฌ์–ด ๊ฒ€์ƒ‰: search= ์˜ˆ) ๋งจํˆฌ๋งจ +์•„๋””๋‹ค์Šค => ๋งจํˆฌ๋งจ์ด ํฌํ•จ๋œ ๋ฌธ์„œ์—์„œ..

Elastic Search 2022.02.15