Vector Database

Elasticsearch Call Api

Import thư viện

import requests

Insert to Inddex

requests.post(url = 'http://localhost:9200/author/_doc/1', json={
    'name': 'Phan Châu Tài',
    'score': 9.4  
})

Select by one

res = requests.get(url='http://localhost:9200/author/_doc/1')
res.text

Insert bulk

headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
res = requests.post(url = 'http://localhost:9200/author/_bulk', data='''
    { "index": { "_id": 5} }
    { "name": "Huy Văn Trương", "score": 8.3 }
    { "index": { "_id": 6} }
    { "name": "Trang Y Hạ", "score": 7.6 }
    { "index": { "_id": 7} }
    { "name": "Hai Hùng SG", "score": "6.7" }
''', headers=headers)
res.text

Select All

q = {
    "query": {
        "match_all": {}
    }
}
res = requests.get(url = 'http://localhost:9200/author/_search', json = q)