October 19, 2024

Search Index

query = dict(
    query={
        'match': {
            'sentence': 'keyword1'
        }
    }
)

res = requests.get(
    f"{url}/{index}"
    headers={'Content-Type': 'application/json'},
    json=query
)

Update Index

document = dict(data='data1')
requests.put(
    f"{url}/{index}/_doc/_id"
    headers={'Content-Type': 'application/json'},
    json=document
)

Delete Index

res = requests.delete(f"{url}/{index}")

Check Index Exsistence

res = requests.head(f"{url}/{index}")
if res.status_code != 200:
    raise Error('')

Create new Index

res = requests.put(
    f"{url}/{index}"
    headers={'Content-Type': 'application/json'},
    json=tokenizer_mapping
)
if res.json()['acknowledged'] is False:
    raise Error('')