from datetime import datetime
# from collections import Mapping
from elasticsearch6 import Elasticsearch
es = Elasticsearch("http://localhost:9200")
# doc = {
# 'author': 'kimchi',
# 'text': 'Elasticsearch: cool bossam kimchi',
# 'timestamp': datetime.now(),
# }
# es.indices.create(index='my-index', ignore=400)
# resp = es.index(index="my-index", doc_type="test_type", id=42, body=doc)
# print(resp['result'])
# print(es.get(index="movie", doc_type="_doc", id=1))
script_query = {
"match": {
"title.nori": "미션"
}
}
search_result = es.search(index="movie", body={"query": script_query})
result = search_result["hits"]["hits"]
print(result)
수행 결과
[{'_index': 'movie', '_type': '_doc', '_id': '3', '_score': 0.2876821, '_source': {'movieId': 'm003', 'title': '미션 임파서블: 데드 레코딩', 'synopsis': '가장 위험한 작전, 그의 마지막 선택 모든 인류를 위협할 새로운 무기를 추적하게 된 에단 헌트(톰 크루즈)와 IMF팀은 이 무기가 인류의 미래를 통제할 수 있다는 사실을 알게 된다.'}}]
"추적"도 검색이 됨
script_query = {
"match": {
"synopsis.nori": "추적"
}
}
search_result = es.search(index="movie", body={"query": script_query})
result = search_result["hits"]["hits"]
print(result)
'python' 카테고리의 다른 글
| Chatgpt Completion create 메소드 정리 (0) | 2023.11.16 |
|---|---|
| Python + ChatGPT(gpt-3.5-turbo용으로 변경) (0) | 2023.11.16 |
| Chat GPT + Python (1) | 2023.11.09 |
| FastApi + ElasticSearch로 간단한 영화검색 만들기 (0) | 2023.07.30 |
| Elastic Search Python 연결 (0) | 2023.07.29 |
