Standard library · Database

db/elasticsearch

An Elasticsearch and OpenSearch client: documents, search, aggregations, bulk, SQL and index management.

import db.elasticsearch

Elasticsearch is a search engine and document store spoken to with JSON over HTTP. This package is written in Salam on top of net.httpx and tls, with no outside library. It works with Elasticsearch 7 and 8, Elastic Cloud (ConnectCloud) and OpenSearch; SQL and point in time calls switch to the OpenSearch endpoints by themselves. A client can list several nodes: it rotates over them, skips a node that refuses connections for DEAD_NODE_MS, and retries on 502, 503 and 504. Documents and query clauses are plain JSON text, so you can mix the builders here with JSON you write by hand, and Perform reaches every API that has no function of its own. After any call, Error, ErrorType and Status describe what the server said. The examples need a running cluster, so they are only checked.

Types

Config

struct Config
Everything a client needs: nodes, credentials, TLS, timeout, retries and extra headers.
NameTypeDescription
nodesVectorNode URLs; each may list several separated by commas.
cloud_idstr = ""An Elastic Cloud id, used before nodes.
usernamestr = ""The user for basic authentication.
passwordstr = ""The password for basic authentication.
api_keystr = ""An API key, encoded or id:key; wins over basic authentication.
bearerstr = ""A bearer token, such as a service account token.
ca_filestr = ""A PEM file of the CA that signed the cluster certificate, for example http_ca.crt.
insecurebool = falseSkip TLS certificate checks. Only for local testing.
timeout_msint = 30000The connect and read timeout of one request in milliseconds; 0 waits forever.
max_retriesint = 3How many more nodes to try after a connection failure or a 502, 503 or 504.
headersHashMapExtra headers sent with every request.
db-elasticsearch-Client.salam
import db.elasticsearch

func main:
    mut cfg := elasticsearch.DefaultConfig()
    cfg.username = "elastic"
    cfg.password = "s3cret"
    cfg.ca_file = "/etc/elasticsearch/certs/http_ca.crt"
    cfg.timeout_ms = 10000
    cfg.headers.put("X-Opaque-Id", "salam-docs")
    mut c := elasticsearch.NewClient(cfg)
    if not elasticsearch.Ping(c):
        println "cannot reach elasticsearch:", elasticsearch.Error(c)
        ret
    end
    info := elasticsearch.GetInfo(c)
    println info.distribution, info.version, elasticsearch.ClusterHealth(c).status

    mapping := `{"mappings":{"properties":{"title":{"type":"text"},"year":{"type":"integer"}}}}`
    if not elasticsearch.IndexExists(c, "books"):
        elasticsearch.CreateIndex(c, "books", mapping)
    end
    w := elasticsearch.IndexWith(c, "books", "1", `{"title":"Shahnameh","year":1010}`, elasticsearch.Options { refresh = elasticsearch.REFRESH_WAIT_FOR })
    println w.result, w.version

    d := elasticsearch.Get(c, "books", "1")
    if d.found: println d.source end
    u := elasticsearch.UpdateWith(c, "books", "1", `{"year":1011}`, elasticsearch.Options { if_seq_no = d.seq_no, if_primary_term = d.primary_term })
    if not u.ok: println "conflict:", elasticsearch.ErrorType(c) end
    elasticsearch.UpdateScript(c, "books", "1", "ctx._source.year += params.n", `{"n": 1}`)
    println elasticsearch.Exists(c, "books", "1"), elasticsearch.Count(c, "books", "")

    r := elasticsearch.Perform(c, "GET", "/_cat/health?format=json", "")
    println r.status, r.body
    elasticsearch.Delete(c, "books", "1")
    elasticsearch.Close(c)
end

Client

struct Client
A client handle. It is cheap to pass by value; free it with Close.
NameTypeDescription
handlevoid*The internal state pointer.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Response

struct Response
The raw answer of Perform: status, body and the parsed error envelope.
NameTypeDescription
statusint = 0The HTTP status, or the status reported for this item.
okbool = falseWhether it succeeded.
bodystr = ""The response body.
errorstr = ""The error text, empty on success.
error_typestr = ""The Elasticsearch error.type.
error_reasonstr = ""The Elasticsearch error.reason.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Options

struct Options
Optional request parameters shared by the write calls: refresh, routing, pipeline, optimistic concurrency and more.
NameTypeDescription
refreshstr = ""true, wait_for or false; see the REFRESH_* constants.
routingstr = ""A custom routing value.
pipelinestr = ""An ingest pipeline to run first.
timeoutstr = ""A server side timeout such as 30s.
wait_for_active_shardsstr = ""How many shard copies must be active, or all.
sourcestr = ""Source filtering: for Options a comma list of fields, for SearchRequest the fields to return; on results the raw _source JSON.
conflictsstr = ""proceed to skip version conflicts in by query operations.
if_seq_noi64 = -1Only write when the document still has this sequence number; -1 turns it off.
if_primary_termi64 = -1The primary term that goes with if_seq_no.
retry_on_conflictint = -1How many times an update retries on a version conflict; -1 leaves the default.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

WriteResult

struct WriteResult
The outcome of indexing, creating, updating or deleting one document.
NameTypeDescription
okbool = falseWhether it succeeded.
statusint = 0The HTTP status, or the status reported for this item.
indexstr = ""The index name.
idstr = ""The document id.
resultstr = ""created, updated, deleted, noop or not_found.
versioni64 = 0The document version, or the cluster version for Info.
seq_noi64 = -1The sequence number, for optimistic concurrency; -1 when unknown.
primary_termi64 = 0The primary term, for optimistic concurrency.
errorstr = ""The error text, empty on success.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Document

struct Document
One fetched document with its metadata and raw _source.
NameTypeDescription
foundbool = falseWhether the document exists.
indexstr = ""The index name.
idstr = ""The document id.
versioni64 = 0The document version, or the cluster version for Info.
seq_noi64 = -1The sequence number, for optimistic concurrency; -1 when unknown.
primary_termi64 = 0The primary term, for optimistic concurrency.
sourcestr = ""Source filtering: for Options a comma list of fields, for SearchRequest the fields to return; on results the raw _source JSON.
fieldsstr = ""Stored or runtime fields: raw JSON on results, a field list on SearchRequest.
errorstr = ""The error text, empty on success.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Hit

struct Hit
One search hit.
NameTypeDescription
indexstr = ""The index name.
idstr = ""The document id.
scoref64 = 0The relevance score.
sourcestr = ""Source filtering: for Options a comma list of fields, for SearchRequest the fields to return; on results the raw _source JSON.
sortstr = ""Sort clauses on a request; on a hit the raw sort values, to pass to search_after.
highlightstr = ""Highlighting: the section on a request, the raw fragments on a hit.
fieldsstr = ""Stored or runtime fields: raw JSON on results, a field list on SearchRequest.
rawstr = ""The raw JSON it was parsed from.
db-elasticsearch-Search.salam
import db.elasticsearch

func main:
    c := elasticsearch.Connect("http://localhost:9200")
    mut must := Vector {} as Vector<str>
    must.push(elasticsearch.Match("title", "persian poetry"))
    mut filters := Vector {} as Vector<str>
    filters.push(elasticsearch.Range("year", "900", "1500"))
    filters.push(elasticsearch.Not(elasticsearch.Term("status", "draft")))
    mut aggs := elasticsearch.AddAgg("", "by_author", elasticsearch.SubAggs(elasticsearch.TermsAgg("author", 5), elasticsearch.AddAgg("", "avg_year", elasticsearch.AvgAgg("year"))))
    aggs = elasticsearch.AddAgg(aggs, "newest", elasticsearch.MaxAgg("year"))
    mut sort := Vector {} as Vector<str>
    sort.push(elasticsearch.SortDesc("year"))
    mut fields := Vector {} as Vector<str>
    fields.push("title")
    req := elasticsearch.SearchRequest {
        query = elasticsearch.Filtered(elasticsearch.And(must), filters), size = 10, sort = sort, aggs = aggs, highlight = elasticsearch.Highlight(fields)
    }
    res := elasticsearch.Search(c, "books", req)
    if not res.ok:
        println elasticsearch.Error(c)
        ret
    end
    println res.total, res.total_relation, res.took
    each h in res.hits:
        println h.id, h.score, h.source, h.highlight
    end
    println elasticsearch.AggValue(res, "newest")
    each b in elasticsearch.AggBuckets(res, "by_author"):
        println b.key, b.doc_count, elasticsearch.AggValueIn(b.raw, "avg_year")
    end

    mut page := elasticsearch.SearchScroll(c, "books", elasticsearch.SearchRequest { query = elasticsearch.MatchAll(), size = 500 }, "1m")
    until page.hits.len() > 0:
        println "page of", page.hits.len()
        page = elasticsearch.Scroll(c, page.scroll_id, "1m")
    end
    elasticsearch.ClearScroll(c, page.scroll_id)

    pit := elasticsearch.OpenPit(c, "books", "1m")
    first := elasticsearch.Search(c, "", elasticsearch.SearchRequest { pit_id = pit, size = 100, sort = sort })
    if first.hits.len() > 0:
        last := first.hits.get(first.hits.len() - 1)
        next := elasticsearch.Search(c, "", elasticsearch.SearchRequest { pit_id = pit, size = 100, sort = sort, search_after = last.sort })
        println next.hits.len()
    end
    elasticsearch.ClosePit(c, pit)
    println elasticsearch.DeleteByQuery(c, "books", elasticsearch.Term("status", "draft"))
end

SearchResult

struct SearchResult
A parsed search response: totals, hits, aggregations and paging ids.
NameTypeDescription
okbool = falseWhether it succeeded.
statusint = 0The HTTP status, or the status reported for this item.
tooki64 = 0Milliseconds the server spent.
timed_outbool = falseWhether the server timed out.
totali64 = 0The number of matching documents.
total_relationstr = ""eq when total is exact, gte when it is a lower bound.
max_scoref64 = 0The best score.
hitsVectorThe hits of this page.
aggregationsstr = ""The raw aggregations JSON.
suggeststr = ""Suggesters: the section on a request, the raw result on a response.
scroll_idstr = ""The id for the next Scroll.
pit_idstr = ""A point in time id: on a request to search it, on a result the refreshed id.
rawstr = ""The raw JSON it was parsed from.
errorstr = ""The error text, empty on success.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

SearchRequest

struct SearchRequest
A search request; SearchBody turns it into JSON. Empty fields are left out.
NameTypeDescription
querystr = ""The query clause JSON; empty matches everything.
fromint = -1The offset of the first hit; -1 leaves it out.
sizeint = -1How many hits to return; -1 leaves it out.
sortVectorSort clauses on a request; on a hit the raw sort values, to pass to search_after.
sourceVectorSource filtering: for Options a comma list of fields, for SearchRequest the fields to return; on results the raw _source JSON.
source_excludesVectorFields to leave out of _source.
no_sourcebool = falseReturn no _source at all.
fieldsVectorStored or runtime fields: raw JSON on results, a field list on SearchRequest.
aggsstr = ""The aggregations object, built with AddAgg.
highlightstr = ""Highlighting: the section on a request, the raw fragments on a hit.
post_filterstr = ""A filter applied after aggregations.
knnstr = ""A Knn clause for vector search.
collapsestr = ""A field to collapse hits on, one hit per value.
suggeststr = ""Suggesters: the section on a request, the raw result on a response.
search_afterstr = ""The raw sort values of the last hit of the previous page.
pit_idstr = ""A point in time id: on a request to search it, on a result the refreshed id.
pit_keep_alivestr = ""How long to keep the point in time alive, such as 1m.
track_total_hitsstr = ""true for an exact total, or a number as the counting limit.
min_scorestr = ""Leave out hits scoring below this.
timeoutstr = ""A server side timeout such as 30s.
extraVectorRaw members added to the body, such as "explain": true.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Bucket

struct Bucket
One bucket of a bucket aggregation.
NameTypeDescription
keystr = ""The bucket key, or key_as_string when there is one.
doc_counti64 = 0How many documents fell into the bucket.
rawstr = ""The raw bucket JSON, for sub aggregations with AggValueIn.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Bulk

struct Bulk
A bulk request being built; add actions with the Bulk* functions.
NameTypeDescription
linesVectorThe NDJSON lines so far.
countint = 0How many actions were added.
db-elasticsearch-Bulk.salam
import str
import db.elasticsearch

func main:
    c := elasticsearch.Connect("http://localhost:9200")
    mut b := elasticsearch.NewBulk()
    repeat 1000 in i:
        id := str.FromInt(i as i64)
        elasticsearch.BulkIndex(b, "logs", id, `{"line":` + id + `,"level":"info"}`)
    end
    elasticsearch.BulkUpdate(b, "logs", "7", `{"level":"warn"}`)
    elasticsearch.BulkUpsert(b, "logs", "new", `{"line":-1}`)
    elasticsearch.BulkDelete(b, "logs", "8")
    println elasticsearch.BulkLen(b)
    res := elasticsearch.RunBulkWith(c, "", b, elasticsearch.Options { refresh = elasticsearch.REFRESH_TRUE })
    println res.ok, res.succeeded, res.failed, res.took
    if res.errors:
        each it in res.items:
            if not it.ok: println it.action, it.id, it.status, it.error_type, it.error_reason end
        end
    end
    elasticsearch.BulkReset(b)
end

BulkItem

struct BulkItem
The result of one action in a bulk request.
NameTypeDescription
actionstr = ""index, create, update or delete.
indexstr = ""The index name.
idstr = ""The document id.
statusint = 0The HTTP status, or the status reported for this item.
okbool = falseWhether it succeeded.
resultstr = ""created, updated, deleted, noop or not_found.
versioni64 = 0The document version, or the cluster version for Info.
error_typestr = ""The Elasticsearch error.type.
error_reasonstr = ""The Elasticsearch error.reason.

The example for this item is shown with the ones above: db-elasticsearch-Bulk.salam

BulkResult

struct BulkResult
The result of a bulk request, with one item per action.
NameTypeDescription
okbool = falseWhether it succeeded.
statusint = 0The HTTP status, or the status reported for this item.
tooki64 = 0Milliseconds the server spent.
errorsbool = falseWhether any action failed.
succeededint = 0How many actions succeeded.
failedint = 0How many actions failed.
itemsVectorOne result per action, in order.
errorstr = ""The error text, empty on success.

The example for this item is shown with the ones above: db-elasticsearch-Bulk.salam

Info

struct Info
What the root endpoint says about the cluster.
NameTypeDescription
okbool = falseWhether it succeeded.
namestr = ""The name of the node that answered.
cluster_namestr = ""The cluster name.
cluster_uuidstr = ""The cluster uuid.
versionstr = ""The server version number.
distributionstr = ""elasticsearch or opensearch.
build_flavorstr = ""The build flavor, such as default.
lucene_versionstr = ""The Lucene version.
taglinestr = ""The tagline the server sends.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Health

struct Health
Cluster health.
NameTypeDescription
okbool = falseWhether it succeeded.
cluster_namestr = ""The cluster name.
statusstr = ""green, yellow or red.
timed_outbool = falseWhether the server timed out.
nodesint = 0The number of nodes.
data_nodesint = 0The number of data nodes.
active_primary_shardsint = 0Active primary shards.
active_shardsint = 0Active shards.
relocating_shardsint = 0Shards being moved.
initializing_shardsint = 0Shards being initialized.
unassigned_shardsint = 0Shards with no node.
pending_tasksint = 0Cluster tasks waiting.
active_shards_percentf64 = 0The percent of shards that are active.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

IndexInfo

struct IndexInfo
One row of CatIndices.
NameTypeDescription
healthstr = ""green, yellow or red.
statusstr = ""open or close.
indexstr = ""The index name.
uuidstr = ""The index uuid.
primariesint = 0The number of primary shards.
replicasint = 0The number of replicas.
docs_counti64 = 0The number of documents.
docs_deletedi64 = 0Deleted documents not yet merged away.
store_sizestr = ""The size on disk in bytes.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

SqlRows

struct SqlRows
SQL query results; implements db.Rows and fetches further pages with the cursor as you call Next.
NameTypeDescription
handlevoid*The internal state pointer.
db-elasticsearch-Sql.salam
import db
import db.elasticsearch

func report(conn: dyn db.Connection):
    rows := conn.Query("SELECT level, COUNT(*) AS n FROM logs GROUP BY level")
    until rows.Next():
        println rows.Text(0), rows.Int(1)
    end
    rows.Close()
end

func main:
    c := elasticsearch.Connect("http://localhost:9200")
    mut params := Vector {} as Vector<str>
    params.push("100")
    mut rows := elasticsearch.SqlWith(c, "SELECT line, level FROM logs WHERE line < ? ORDER BY line", params, 50)
    println rows.ColumnCount(), rows.ColumnName(0), rows.ColumnTypeName(0), rows.ColumnType(0) == db.TYPE_INT
    until rows.Next():
        println rows.Int64(0), rows.Text(1), rows.IsNull(1)
    end
    rows.Close()
    print elasticsearch.SqlText(c, "SELECT level FROM logs LIMIT 3")
    println elasticsearch.SqlTranslate(c, "SELECT line FROM logs WHERE level = 'warn'")
    report(elasticsearch.Conn(c))
end

Ok

func Ok(): bool
Whether the query succeeded.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Error

func Error(): str
The error of the query, empty on success.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Next

func Next(): bool
Moves to the next row, fetching the next page when needed.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

ColumnCount

func ColumnCount(): int
The number of columns.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

ColumnName

func ColumnName(col: int): str
The name of a column.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

ColumnTypeName

func ColumnTypeName(col: int): str
The Elasticsearch type of a column, such as long or keyword.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

ColumnType

func ColumnType(col: int): int
The db.TYPE_* kind of a column, TYPE_NULL for a null cell.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

IsNull

func IsNull(col: int): bool
Whether a cell of the current row is null.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Text

func Text(col: int): str
A cell as text; empty for null.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Int

func Int(col: int): int
A cell as an int.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Int64

func Int64(col: int): i64
A cell as an i64.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Float

func Float(col: int): f64
A cell as a float.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Close

func Close(): int
Frees the rows and closes an open cursor.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Database

struct Database
A client seen through db.Connection, so code written for the db interfaces can read Elasticsearch with SQL.
NameTypeDescription
handlevoid*The internal state pointer.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Kind

func Kind(): str
Always db.ELASTICSEARCH.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Ok

func Ok(): bool
Whether the client is valid.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Ping

func Ping(): bool
Whether the cluster answers.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Exec

func Exec(_sql: str): int
Always -1: Elasticsearch SQL is read only. Write with Index, Bulk or DeleteByQuery.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Query

func Query(sql: str): dyn db.Rows
Runs a SQL query.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Begin

func Begin(): dyn db.Tx
Returns a transaction whose calls all fail; Elasticsearch has no transactions.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

LastInsertId

func LastInsertId(): i64
Always 0.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Changes

func Changes(): i64
Always 0.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Error

func Error(): str
The error of the last call.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Quote

func Quote(s: str): str
Quotes a string literal for SQL.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Close

func Close(): int
Closes the client.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Txn

struct Txn
The transaction Database.Begin returns. Elasticsearch has no transactions, so every call fails.
NameTypeDescription
handlevoid*The internal state pointer.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Ok

func Ok(): bool
Always false.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Exec

func Exec(_sql: str): int
Always -1.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Query

func Query(_sql: str): dyn db.Rows
Returns empty rows.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Commit

func Commit(): int
Always -1.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Rollback

func Rollback(): int
Always -1.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Constants and variables

DEFAULT_URL

const DEFAULT_URL: str = "http://localhost:9200"
The node used when a config lists none: http://localhost:9200.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

DEFAULT_PORT

const DEFAULT_PORT: i32 = 9200
The port used when a node URL has none: 9200.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

DEAD_NODE_MS

const DEAD_NODE_MS: i32 = 60000
How long, in milliseconds, a node that refused a connection is skipped before it is tried again.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

REFRESH_TRUE

const REFRESH_TRUE: str = "true"
refresh value: make the change searchable right away.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

REFRESH_WAIT_FOR

const REFRESH_WAIT_FOR: str = "wait_for"
refresh value: wait until the next refresh makes the change searchable.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

REFRESH_FALSE

const REFRESH_FALSE: str = "false"
refresh value: return without waiting for a refresh (the default).

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Functions

MatchAll

func MatchAll(): str
A query matching every document.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Match

func Match(field: str, text: str): str
A full text match query.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

MatchAnd

func MatchAnd(field: str, text: str): str
A match query that needs every word.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

MatchFuzzy

func MatchFuzzy(field: str, text: str): str
A match query with automatic fuzziness, forgiving typos.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

MatchPhrase

func MatchPhrase(field: str, text: str): str
A query for the exact phrase.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

MatchPhrasePrefix

func MatchPhrasePrefix(field: str, text: str): str
A phrase query whose last word is a prefix, for search as you type.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

MultiMatch

func MultiMatch(text: str, fields: Vector<str>): str
A match over several fields; a field may carry a boost like title^2.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Term

func Term(field: str, value: str): str
An exact value term query.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

TermInt

func TermInt(field: str, value: i64): str
A term query on a number.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

TermBool

func TermBool(field: str, value: bool): str
A term query on a boolean.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Terms

func Terms(field: str, values: Vector<str>): str
Matches any of several exact values.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Range

func Range(field: str, low: str, high: str): str
An inclusive range query; an empty bound is open. Bounds are numbers or dates as text.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

RangeExclusive

func RangeExclusive(field: str, low: str, high: str): str
A range query that excludes its bounds.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

FieldExists

func FieldExists(field: str): str
Matches documents that have a value in the field.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Prefix

func Prefix(field: str, value: str): str
Matches values that start with a prefix.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Wildcard

func Wildcard(field: str, pattern: str): str
A wildcard query with * and ?.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Regexp

func Regexp(field: str, pattern: str): str
A regular expression query.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Fuzzy

func Fuzzy(field: str, value: str): str
A fuzzy term query.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

QueryString

func QueryString(query: str): str
A query_string query in Lucene syntax.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

SimpleQueryString

func SimpleQueryString(query: str, fields: Vector<str>): str
A forgiving simple_query_string query for user input, over the given fields.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Bool

func Bool(must: Vector<str>, filter: Vector<str>, should: Vector<str>, must_not: Vector<str>): str
A bool query from must, filter, should and must_not clauses; any list may be empty.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

And

func And(clauses: Vector<str>): str
Matches when every clause matches.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Or

func Or(clauses: Vector<str>): str
Matches when at least one clause matches.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Not

func Not(clause: str): str
Matches when the clause does not.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Filtered

func Filtered(query: str, filters: Vector<str>): str
A scored query narrowed by unscored filters.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

ConstantScore

func ConstantScore(filter: str): str
Runs a filter and gives every match the same score.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Nested

func Nested(path: str, query: str): str
A query on nested objects under a path.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

GeoDistance

func GeoDistance(field: str, lat: f64, lon: f64, distance: str): str
Matches geo points within a distance, such as 10km, of a point.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Knn

func Knn(field: str, vector: Vector<f64>, k: int, num_candidates: int): str
An approximate nearest neighbour clause for dense vector search; put it in SearchRequest.knn.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

SortAsc

func SortAsc(field: str): str
An ascending sort clause.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

SortDesc

func SortDesc(field: str): str
A descending sort clause.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Highlight

func Highlight(fields: Vector<str>): str
A highlight section for the given fields.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

TermsAgg

func TermsAgg(field: str, size: int): str
A terms bucket aggregation, the top values of a field.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

MinAgg

func MinAgg(field: str): str
The smallest value of a field.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

MaxAgg

func MaxAgg(field: str): str
The largest value of a field.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

ValueCountAgg

func ValueCountAgg(field: str): str
How many values a field has.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

CardinalityAgg

func CardinalityAgg(field: str): str
The approximate number of distinct values.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

StatsAgg

func StatsAgg(field: str): str
Count, min, max, average and sum together.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

HistogramAgg

func HistogramAgg(field: str, interval: f64): str
Buckets of a fixed numeric width.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

DateHistogramAgg

func DateHistogramAgg(field: str, calendar_interval: str): str
Buckets per calendar interval such as day or month.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

FilterAgg

func FilterAgg(query: str): str
A single bucket of the documents matching a query.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

TopHitsAgg

func TopHitsAgg(size: int): str
The best hits inside each bucket.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

AddAgg

func AddAgg(aggs: str, name: str, agg: str): str
Adds a named aggregation to an aggregations object; start from an empty string.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

SubAggs

func SubAggs(agg: str, aggs: str): str
Nests an aggregations object under a bucket aggregation.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

AddMember

func AddMember(obj: str, key: str, raw: str): str
Adds a raw member to a JSON object, for options without a helper.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

SearchBody

func SearchBody(req: SearchRequest): str
The JSON body of a SearchRequest.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

BulkIndex

func BulkIndex(b &: Bulk, index: str, id: str, doc: str)
Adds an index action; an empty id lets Elasticsearch pick one. Multi line JSON is minified.

The example for this item is shown with the ones above: db-elasticsearch-Bulk.salam

BulkCreate

func BulkCreate(b &: Bulk, index: str, id: str, doc: str)
Adds a create action, which fails for an existing id.

The example for this item is shown with the ones above: db-elasticsearch-Bulk.salam

BulkUpdate

func BulkUpdate(b &: Bulk, index: str, id: str, partial: str)
Adds a partial update action.

The example for this item is shown with the ones above: db-elasticsearch-Bulk.salam

BulkUpsert

func BulkUpsert(b &: Bulk, index: str, id: str, doc: str)
Adds an update that creates the document when it is missing.

The example for this item is shown with the ones above: db-elasticsearch-Bulk.salam

BulkDelete

func BulkDelete(b &: Bulk, index: str, id: str)
Adds a delete action.

The example for this item is shown with the ones above: db-elasticsearch-Bulk.salam

BulkLen

func BulkLen(b: Bulk): int
How many actions the bulk request holds.

The example for this item is shown with the ones above: db-elasticsearch-Bulk.salam

BulkBody

func BulkBody(b: Bulk): str
The NDJSON body of the bulk request.

The example for this item is shown with the ones above: db-elasticsearch-Bulk.salam

BulkReset

func BulkReset(b &: Bulk)
Empties the bulk request for reuse.

The example for this item is shown with the ones above: db-elasticsearch-Bulk.salam

ParseBulkResult

func ParseBulkResult(body: str): BulkResult
Parses a raw bulk response.

The example for this item is shown with the ones above: db-elasticsearch-Bulk.salam

RunBulk

func RunBulk(c: Client, b: Bulk): BulkResult
Sends the bulk request. ok is false when any action failed; check items.

The example for this item is shown with the ones above: db-elasticsearch-Bulk.salam

RunBulkWith

func RunBulkWith(c: Client, index: str, b: Bulk, opts: Options): BulkResult
RunBulk with a default index for actions that name none, and options.

The example for this item is shown with the ones above: db-elasticsearch-Bulk.salam

GetInfo

func GetInfo(c: Client): Info
The name, version and distribution of the cluster; distribution is opensearch on OpenSearch.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

ClusterHealth

func ClusterHealth(c: Client): Health
The health of the cluster.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

WaitForStatus

func WaitForStatus(c: Client, status: str, timeout: str): Health
Waits until the cluster reaches a status such as yellow, or the timeout runs out; ok is false on timeout.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

ClusterStats

func ClusterStats(c: Client): str
The raw cluster statistics JSON.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

NodesInfo

func NodesInfo(c: Client): str
The raw node information JSON.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

CatIndices

func CatIndices(c: Client, pattern: str): Vector<IndexInfo>
The indices that match a pattern (all of them when it is empty), sorted by name.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

CreateIndex

func CreateIndex(c: Client, index: str, body: str): bool
Creates an index with an optional settings and mappings body.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

DeleteIndex

func DeleteIndex(c: Client, index: str): bool
Deletes an index.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

IndexExists

func IndexExists(c: Client, index: str): bool
Whether an index (or alias) exists.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

GetIndex

func GetIndex(c: Client, index: str): str
The raw JSON definition of an index.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

GetMapping

func GetMapping(c: Client, index: str): str
The raw mappings JSON of an index.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

PutMapping

func PutMapping(c: Client, index: str, body: str): bool
Adds fields to the mappings of an index.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

GetSettings

func GetSettings(c: Client, index: str): str
The raw settings JSON of an index.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

PutSettings

func PutSettings(c: Client, index: str, body: str): bool
Changes dynamic settings of an index.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Refresh

func Refresh(c: Client, index: str): bool
Makes recent changes searchable; an empty index refreshes all.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Flush

func Flush(c: Client, index: str): bool
Flushes an index to disk; an empty index flushes all.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

ForceMerge

func ForceMerge(c: Client, index: str, max_segments: int): bool
Merges segments, down to max_segments when it is above 0.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

OpenIndex

func OpenIndex(c: Client, index: str): bool
Opens a closed index.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

CloseIndex

func CloseIndex(c: Client, index: str): bool
Closes an index.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

PutAlias

func PutAlias(c: Client, index: str, alias: str): bool
Points an alias at an index.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

DeleteAlias

func DeleteAlias(c: Client, index: str, alias: str): bool
Removes an alias from an index.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

AliasExists

func AliasExists(c: Client, alias: str): bool
Whether an alias exists.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

GetAlias

func GetAlias(c: Client, alias: str): Vector<str>
The indices an alias points at.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

SwapAlias

func SwapAlias(c: Client, alias: str, old_index: str, new_index: str): bool
Moves an alias from one index to another atomically, the usual zero downtime reindex step.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

UpdateAliases

func UpdateAliases(c: Client, actions: str): bool
Runs a raw JSON array of alias actions atomically.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

PutIndexTemplate

func PutIndexTemplate(c: Client, name: str, body: str): bool
Creates or replaces a composable index template.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

DeleteIndexTemplate

func DeleteIndexTemplate(c: Client, name: str): bool
Deletes an index template.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

IndexTemplateExists

func IndexTemplateExists(c: Client, name: str): bool
Whether an index template exists.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Reindex

func Reindex(c: Client, source: str, dest: str): i64
Copies every document of one index into another and returns how many were written; -1 on error.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Analyze

func Analyze(c: Client, index: str, analyzer: str, text: str): Vector<str>
The tokens an analyzer makes of a text; an empty index uses the cluster analyzers.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Index

func Index(c: Client, index: str, id: str, doc: str): WriteResult
Stores a document. With an empty id Elasticsearch picks one, returned in id.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

IndexWith

func IndexWith(c: Client, index: str, id: str, doc: str, opts: Options): WriteResult
Index with options.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Create

func Create(c: Client, index: str, id: str, doc: str): WriteResult
Stores a document only if its id is new; a duplicate fails with status 409.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

CreateWith

func CreateWith(c: Client, index: str, id: str, doc: str, opts: Options): WriteResult
Create with options.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Get

func Get(c: Client, index: str, id: str): Document
Fetches a document by id. A missing document has found false and no error.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

GetWith

func GetWith(c: Client, index: str, id: str, opts: Options): Document
Get with options; source filters the returned fields.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

GetSource

func GetSource(c: Client, index: str, id: str): str
Only the _source of a document, empty when it is missing.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Exists

func Exists(c: Client, index: str, id: str): bool
Whether a document exists.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Update

func Update(c: Client, index: str, id: str, partial: str): WriteResult
Merges a partial document into an existing one.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

UpdateWith

func UpdateWith(c: Client, index: str, id: str, partial: str, opts: Options): WriteResult
Update with options, including if_seq_no and if_primary_term for optimistic concurrency.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Upsert

func Upsert(c: Client, index: str, id: str, doc: str): WriteResult
Updates a document, or creates it when it does not exist.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Script

func Script(source: str, params: str): str
A painless script object with optional raw JSON params.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

UpdateScript

func UpdateScript(c: Client, index: str, id: str, source: str, params: str): WriteResult
Updates a document with a painless script.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Delete

func Delete(c: Client, index: str, id: str): WriteResult
Deletes a document by id.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

DeleteWith

func DeleteWith(c: Client, index: str, id: str, opts: Options): WriteResult
Delete with options.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

MGet

func MGet(c: Client, index: str, ids: Vector<str>): Vector<Document>
Fetches several documents in one request, in the order of the ids.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Count

func Count(c: Client, index: str, query: str): i64
The number of documents matching a query (all when it is empty); -1 on error.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

DefaultConfig

func DefaultConfig(): Config
A config for DEFAULT_URL with the default timeout and retries.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

NewClient

func NewClient(cfg: Config): Client
Builds a client from a config. Node URLs may carry credentials (https://user:pass@host:9200) and a path prefix, and one string may list several nodes separated by commas.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Connect

func Connect(url: str): Client
A client for one URL, or several separated by commas.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

ConnectAuth

func ConnectAuth(url: str, username: str, password: str): Client
A client that sends HTTP basic authentication.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

ConnectApiKey

func ConnectApiKey(url: str, api_key: str): Client
A client that authenticates with an API key, either encoded or as id:key.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

ConnectCloud

func ConnectCloud(cloud_id: str, api_key: str): Client
A client for an Elastic Cloud deployment, from its cloud id and an API key.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Ok

func Ok(c: Client): bool
Whether the client has at least one valid node.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Error

func Error(c: Client): str
The error of the last call: the type and reason Elasticsearch sent, or a connection or config error. Empty after a success.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

ErrorType

func ErrorType(c: Client): str
The error.type of the last failed call, for example version_conflict_engine_exception.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

ErrorReason

func ErrorReason(c: Client): str
The error.reason of the last failed call.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Status

func Status(c: Client): int
The HTTP status of the last call, 0 when no answer came.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Nodes

func Nodes(c: Client): Vector<str>
The node URLs the client rotates over.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

AuthHeader

func AuthHeader(c: Client): str
The Authorization header value the client sends.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

DecodeCloudId

func DecodeCloudId(cloud_id: str): str
Turns an Elastic Cloud id into the HTTPS URL of its Elasticsearch endpoint; empty when it cannot be decoded.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Close

func Close(c &: Client)
Frees the client. The handle is null afterwards.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Perform

func Perform(c: Client, method: str, path: str, body: str): Response
Sends any request with a JSON body and returns the raw response. Use it for every API this package does not wrap.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

PerformNdjson

func PerformNdjson(c: Client, method: str, path: str, body: str): Response
Like Perform, with an application/x-ndjson body.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

Distribution

func Distribution(c: Client): str
elasticsearch or opensearch, asked from the server once and remembered.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

IsOpenSearch

func IsOpenSearch(c: Client): bool
Whether the cluster is OpenSearch. SQL and point in time calls pick the right endpoints on their own.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

EncodeBasic

func EncodeBasic(username: str, password: str): str
The base64 of user:password used by basic authentication.

The example for this item is shown with the ones above: db-elasticsearch-Client.salam

ParseSearchResult

func ParseSearchResult(body: str): SearchResult
Parses a raw search response, for example one from Perform.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

func Search(c: Client, index: str, req: SearchRequest): SearchResult
Runs a search on an index, a comma separated list, a pattern, or with an empty index on a point in time.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

SearchQuery

func SearchQuery(c: Client, index: str, query: str, size: int): SearchResult
Runs a query and returns up to size hits.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

SearchRaw

func SearchRaw(c: Client, index: str, body: str): SearchResult
Runs a search with a raw JSON body.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

SearchScroll

func SearchScroll(c: Client, index: str, req: SearchRequest, keep_alive: str): SearchResult
Starts a scroll; keep calling Scroll with scroll_id until a page comes back empty.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Scroll

func Scroll(c: Client, scroll_id: str, keep_alive: str): SearchResult
The next page of a scroll.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

ClearScroll

func ClearScroll(c: Client, scroll_id: str): bool
Releases a scroll early.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

OpenPit

func OpenPit(c: Client, index: str, keep_alive: str): str
Opens a point in time on an index for consistent deep paging with search_after.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

ClosePit

func ClosePit(c: Client, pit_id: str): bool
Closes a point in time.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

DeleteByQuery

func DeleteByQuery(c: Client, index: str, query: str): i64
Deletes every document matching a query and returns how many; -1 on error.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

DeleteByQueryWith

func DeleteByQueryWith(c: Client, index: str, query: str, opts: Options): i64
DeleteByQuery with options such as refresh and conflicts.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

UpdateByQuery

func UpdateByQuery(c: Client, index: str, query: str, script: str): i64
Runs a script on every document matching a query and returns how many changed; -1 on error.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

UpdateByQueryWith

func UpdateByQueryWith(c: Client, index: str, query: str, script: str, opts: Options): i64
UpdateByQuery with options.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

MSearch

func MSearch(c: Client, index: str, bodies: Vector<str>): Vector<SearchResult>
Runs several searches in one request; each result has its own ok and error.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

AggValueIn

func AggValueIn(aggs: str, name: str): f64
The value of a metric aggregation inside raw aggregations JSON, such as Bucket.raw.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

AggBucketsIn

func AggBucketsIn(aggs: str, name: str): Vector<Bucket>
The buckets of a bucket aggregation inside raw aggregations JSON.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

AggValue

func AggValue(res: SearchResult, name: str): f64
The value of a metric aggregation in a result.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

AggBuckets

func AggBuckets(res: SearchResult, name: str): Vector<Bucket>
The buckets of a bucket aggregation in a result.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

AggRaw

func AggRaw(res: SearchResult, name: str): str
The raw JSON of one aggregation in a result.

The example for this item is shown with the ones above: db-elasticsearch-Search.salam

Sql

func Sql(c: Client, query: str): SqlRows
Runs a SQL query through Elasticsearch SQL, or the OpenSearch SQL plugin.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

SqlWith

func SqlWith(c: Client, query: str, params: Vector<str>, fetch_size: int): SqlRows
Runs SQL with ? parameters given as raw JSON values, and a page size.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

SqlText

func SqlText(c: Client, query: str): str
The result of a SQL query as a text table (CSV on OpenSearch).

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

SqlTranslate

func SqlTranslate(c: Client, query: str): str
The query DSL a SQL query turns into (the explain plan on OpenSearch).

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam

Conn

func Conn(c: Client): dyn db.Connection
The client as a db.Connection. Closing it closes the client.

The example for this item is shown with the ones above: db-elasticsearch-Sql.salam