Skip to main content

snippets_py

Integration

New integration from credential
elasticsearch = yepcode.integration.elasticsearch('credential-slug')
New integration from plain authentication data
from elasticsearch import Elasticsearch

# Use the params you need for your use case
elasticsearch = Elasticsearch(
cloud_id="your-cloud-id",
# hosts="https://localhost:9200",
# basic_auth=("username", "password"),
api_key="base64EncodedKey",
# bearer_auth="bearerToken",
# Other extra options
)

Add Data to an Index

Add data to an index
doc = {
"character": "Ned Stark",
"quote": "Winter is coming."
}

elasticsearch.index(index="index-name", document=doc)

Search in Index

Search in index
query = {"match": {"someKey": "someValue"}}

result = elasticsearch.search(index="index-name", query=query)

for hit in result['hits']['hits']:
print(hit)

Execute SQL Query

Execute SQL query
result = elasticsearch.sql.query(query= "SELECT * FROM \"search-api-index\" WHERE key='value'")

for column in result['columns']:
print(column)