# 기존 products 인덱스 삭제 DELETE /products
# 인덱스 생성 PUT /products # 매핑 정의 PUT /products/_mappings { "properties": { "name": { "type": "text" } } }
# 인덱스 생성 + 매핑 정의 (자주 쓰이니 정리해두자!) PUT /products { "mappings": { "properties": { "name": { "type": "text" } } } }
# 인덱스 잘 생성됐는 지 확인 GET /products
# 데이터 넣기 POST /products/_create/1 { "name": "Apple 2025 맥북 에어 13 M4 10코어" } POST /products/_create/2 { "name": "Apple 2024 에어팟 4세대" } POST /products/_create/3 { "name": "Apple 2024 아이패드 mini A17 Pro" }
# 'Apple 2024 아이패드'로 검색 GET /products/_search { "query": { "match": { "name": "Apple 2024 아이패드" } } }
{ "took": 7, "timed_out": false, "_shards": { "total": 1, "successful": 1, "skipped": 0, "failed": 0 }, "hits": { "total": { "value": 3, "relation": "eq" }, "max_score": 1.5471337, "hits": [ { "_index": "products", "_id": "3", "_score": 1.5471337, "_source": { "name": "Apple 2024 아이패드 mini A17 Pro" } }, { "_index": "products", "_id": "2", "_score": 0.6860854, "_source": { "name": "Apple 2024 에어팟 4세대" } }, { "_index": "products", "_id": "1", "_score": 0.12180668, "_source": { "name": "Apple 2025 맥북 에어 13 M4 10코어" } } ] } }
Apple 2024 아이패드라고 검색하면 역인덱스를 활용해 일치하는 단어가 많은 도큐먼트를 우선적으로 조회한다.토큰(token) | 도큐먼트 id |
Apple | [1, 2, 3] |
2025 | [1] |
맥북 | [1] |
에어 | [1] |
13 | [1] |
M4 | [1] |
10코어 | [1] |
2024 | [2, 3] |
에어팟 | [2] |
4세대 | [2] |
아이패드 | [3] |
mini | [3] |
A17 | [3] |
Pro | [3] |
id=3 → id=2 → id=1)으로 도큐먼트를 조회한다. 문서 내에서 검색어가 얼마나 자주 등장하냐→ 많이 등장할수록 점수↑
검색어가 전체 문서 중 얼마나 희귀하냐→ 희귀할수록 점수↑ (흔한 단어일수록 점수↓)
문서(필드)가 짧을수록 점수↑→ 검색어가 짧은 문서에서 등장하면 더 관련성 높다고 판단