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| Name | Type | Description |
|---|---|---|
nodes | Vector | Node URLs; each may list several separated by commas. |
cloud_id | str = "" | An Elastic Cloud id, used before nodes. |
username | str = "" | The user for basic authentication. |
password | str = "" | The password for basic authentication. |
api_key | str = "" | An API key, encoded or id:key; wins over basic authentication. |
bearer | str = "" | A bearer token, such as a service account token. |
ca_file | str = "" | A PEM file of the CA that signed the cluster certificate, for example http_ca.crt. |
insecure | bool = false | Skip TLS certificate checks. Only for local testing. |
timeout_ms | int = 30000 | The connect and read timeout of one request in milliseconds; 0 waits forever. |
max_retries | int = 3 | How many more nodes to try after a connection failure or a 502, 503 or 504. |
headers | HashMap | Extra headers sent with every request. |
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)
endClient
struct ClientClose.| Name | Type | Description |
|---|---|---|
handle | void* | The internal state pointer. |
The example for this item is shown with the ones above: db-elasticsearch-Client.salam
Response
struct ResponsePerform: status, body and the parsed error envelope.| Name | Type | Description |
|---|---|---|
status | int = 0 | The HTTP status, or the status reported for this item. |
ok | bool = false | Whether it succeeded. |
body | str = "" | The response body. |
error | str = "" | The error text, empty on success. |
error_type | str = "" | The Elasticsearch error.type. |
error_reason | str = "" | The Elasticsearch error.reason. |
The example for this item is shown with the ones above: db-elasticsearch-Client.salam
Options
struct Options| Name | Type | Description |
|---|---|---|
refresh | str = "" | true, wait_for or false; see the REFRESH_* constants. |
routing | str = "" | A custom routing value. |
pipeline | str = "" | An ingest pipeline to run first. |
timeout | str = "" | A server side timeout such as 30s. |
wait_for_active_shards | str = "" | How many shard copies must be active, or all. |
source | str = "" | Source filtering: for Options a comma list of fields, for SearchRequest the fields to return; on results the raw _source JSON. |
conflicts | str = "" | proceed to skip version conflicts in by query operations. |
if_seq_no | i64 = -1 | Only write when the document still has this sequence number; -1 turns it off. |
if_primary_term | i64 = -1 | The primary term that goes with if_seq_no. |
retry_on_conflict | int = -1 | How 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| Name | Type | Description |
|---|---|---|
ok | bool = false | Whether it succeeded. |
status | int = 0 | The HTTP status, or the status reported for this item. |
index | str = "" | The index name. |
id | str = "" | The document id. |
result | str = "" | created, updated, deleted, noop or not_found. |
version | i64 = 0 | The document version, or the cluster version for Info. |
seq_no | i64 = -1 | The sequence number, for optimistic concurrency; -1 when unknown. |
primary_term | i64 = 0 | The primary term, for optimistic concurrency. |
error | str = "" | The error text, empty on success. |
The example for this item is shown with the ones above: db-elasticsearch-Client.salam
Document
struct Document_source.| Name | Type | Description |
|---|---|---|
found | bool = false | Whether the document exists. |
index | str = "" | The index name. |
id | str = "" | The document id. |
version | i64 = 0 | The document version, or the cluster version for Info. |
seq_no | i64 = -1 | The sequence number, for optimistic concurrency; -1 when unknown. |
primary_term | i64 = 0 | The primary term, for optimistic concurrency. |
source | str = "" | Source filtering: for Options a comma list of fields, for SearchRequest the fields to return; on results the raw _source JSON. |
fields | str = "" | Stored or runtime fields: raw JSON on results, a field list on SearchRequest. |
error | str = "" | The error text, empty on success. |
The example for this item is shown with the ones above: db-elasticsearch-Client.salam
Hit
struct Hit| Name | Type | Description |
|---|---|---|
index | str = "" | The index name. |
id | str = "" | The document id. |
score | f64 = 0 | The relevance score. |
source | str = "" | Source filtering: for Options a comma list of fields, for SearchRequest the fields to return; on results the raw _source JSON. |
sort | str = "" | Sort clauses on a request; on a hit the raw sort values, to pass to search_after. |
highlight | str = "" | Highlighting: the section on a request, the raw fragments on a hit. |
fields | str = "" | Stored or runtime fields: raw JSON on results, a field list on SearchRequest. |
raw | str = "" | The raw JSON it was parsed from. |
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"))
endSearchResult
struct SearchResult| Name | Type | Description |
|---|---|---|
ok | bool = false | Whether it succeeded. |
status | int = 0 | The HTTP status, or the status reported for this item. |
took | i64 = 0 | Milliseconds the server spent. |
timed_out | bool = false | Whether the server timed out. |
total | i64 = 0 | The number of matching documents. |
total_relation | str = "" | eq when total is exact, gte when it is a lower bound. |
max_score | f64 = 0 | The best score. |
hits | Vector | The hits of this page. |
aggregations | str = "" | The raw aggregations JSON. |
suggest | str = "" | Suggesters: the section on a request, the raw result on a response. |
scroll_id | str = "" | The id for the next Scroll. |
pit_id | str = "" | A point in time id: on a request to search it, on a result the refreshed id. |
raw | str = "" | The raw JSON it was parsed from. |
error | str = "" | The error text, empty on success. |
The example for this item is shown with the ones above: db-elasticsearch-Search.salam
SearchRequest
struct SearchRequestSearchBody turns it into JSON. Empty fields are left out.| Name | Type | Description |
|---|---|---|
query | str = "" | The query clause JSON; empty matches everything. |
from | int = -1 | The offset of the first hit; -1 leaves it out. |
size | int = -1 | How many hits to return; -1 leaves it out. |
sort | Vector | Sort clauses on a request; on a hit the raw sort values, to pass to search_after. |
source | Vector | Source filtering: for Options a comma list of fields, for SearchRequest the fields to return; on results the raw _source JSON. |
source_excludes | Vector | Fields to leave out of _source. |
no_source | bool = false | Return no _source at all. |
fields | Vector | Stored or runtime fields: raw JSON on results, a field list on SearchRequest. |
aggs | str = "" | The aggregations object, built with AddAgg. |
highlight | str = "" | Highlighting: the section on a request, the raw fragments on a hit. |
post_filter | str = "" | A filter applied after aggregations. |
knn | str = "" | A Knn clause for vector search. |
collapse | str = "" | A field to collapse hits on, one hit per value. |
suggest | str = "" | Suggesters: the section on a request, the raw result on a response. |
search_after | str = "" | The raw sort values of the last hit of the previous page. |
pit_id | str = "" | A point in time id: on a request to search it, on a result the refreshed id. |
pit_keep_alive | str = "" | How long to keep the point in time alive, such as 1m. |
track_total_hits | str = "" | true for an exact total, or a number as the counting limit. |
min_score | str = "" | Leave out hits scoring below this. |
timeout | str = "" | A server side timeout such as 30s. |
extra | Vector | Raw 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| Name | Type | Description |
|---|---|---|
key | str = "" | The bucket key, or key_as_string when there is one. |
doc_count | i64 = 0 | How many documents fell into the bucket. |
raw | str = "" | 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 BulkBulk* functions.| Name | Type | Description |
|---|---|---|
lines | Vector | The NDJSON lines so far. |
count | int = 0 | How many actions were added. |
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)
endBulkItem
struct BulkItem| Name | Type | Description |
|---|---|---|
action | str = "" | index, create, update or delete. |
index | str = "" | The index name. |
id | str = "" | The document id. |
status | int = 0 | The HTTP status, or the status reported for this item. |
ok | bool = false | Whether it succeeded. |
result | str = "" | created, updated, deleted, noop or not_found. |
version | i64 = 0 | The document version, or the cluster version for Info. |
error_type | str = "" | The Elasticsearch error.type. |
error_reason | str = "" | The Elasticsearch error.reason. |
The example for this item is shown with the ones above: db-elasticsearch-Bulk.salam
BulkResult
struct BulkResult| Name | Type | Description |
|---|---|---|
ok | bool = false | Whether it succeeded. |
status | int = 0 | The HTTP status, or the status reported for this item. |
took | i64 = 0 | Milliseconds the server spent. |
errors | bool = false | Whether any action failed. |
succeeded | int = 0 | How many actions succeeded. |
failed | int = 0 | How many actions failed. |
items | Vector | One result per action, in order. |
error | str = "" | The error text, empty on success. |
The example for this item is shown with the ones above: db-elasticsearch-Bulk.salam
Info
struct Info| Name | Type | Description |
|---|---|---|
ok | bool = false | Whether it succeeded. |
name | str = "" | The name of the node that answered. |
cluster_name | str = "" | The cluster name. |
cluster_uuid | str = "" | The cluster uuid. |
version | str = "" | The server version number. |
distribution | str = "" | elasticsearch or opensearch. |
build_flavor | str = "" | The build flavor, such as default. |
lucene_version | str = "" | The Lucene version. |
tagline | str = "" | The tagline the server sends. |
The example for this item is shown with the ones above: db-elasticsearch-Client.salam
Health
struct Health| Name | Type | Description |
|---|---|---|
ok | bool = false | Whether it succeeded. |
cluster_name | str = "" | The cluster name. |
status | str = "" | green, yellow or red. |
timed_out | bool = false | Whether the server timed out. |
nodes | int = 0 | The number of nodes. |
data_nodes | int = 0 | The number of data nodes. |
active_primary_shards | int = 0 | Active primary shards. |
active_shards | int = 0 | Active shards. |
relocating_shards | int = 0 | Shards being moved. |
initializing_shards | int = 0 | Shards being initialized. |
unassigned_shards | int = 0 | Shards with no node. |
pending_tasks | int = 0 | Cluster tasks waiting. |
active_shards_percent | f64 = 0 | The percent of shards that are active. |
The example for this item is shown with the ones above: db-elasticsearch-Client.salam
IndexInfo
struct IndexInfoCatIndices.| Name | Type | Description |
|---|---|---|
health | str = "" | green, yellow or red. |
status | str = "" | open or close. |
index | str = "" | The index name. |
uuid | str = "" | The index uuid. |
primaries | int = 0 | The number of primary shards. |
replicas | int = 0 | The number of replicas. |
docs_count | i64 = 0 | The number of documents. |
docs_deleted | i64 = 0 | Deleted documents not yet merged away. |
store_size | str = "" | The size on disk in bytes. |
The example for this item is shown with the ones above: db-elasticsearch-Client.salam
SqlRows
struct SqlRowsdb.Rows and fetches further pages with the cursor as you call Next.| Name | Type | Description |
|---|---|---|
handle | void* | The internal state pointer. |
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))
endOk
func Ok(): boolThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Error
func Error(): strThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Next
func Next(): boolThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
ColumnCount
func ColumnCount(): intThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
ColumnName
func ColumnName(col: int): strThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
ColumnTypeName
func ColumnTypeName(col: int): strlong or keyword.The example for this item is shown with the ones above: db-elasticsearch-Sql.salam
ColumnType
func ColumnType(col: int): intdb.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): boolThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Text
func Text(col: int): strThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Int
func Int(col: int): intThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Int64
func Int64(col: int): i64The example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Float
func Float(col: int): f64The example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Close
func Close(): intThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Database
struct Databasedb.Connection, so code written for the db interfaces can read Elasticsearch with SQL.| Name | Type | Description |
|---|---|---|
handle | void* | The internal state pointer. |
The example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Kind
func Kind(): strdb.ELASTICSEARCH.The example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Ok
func Ok(): boolThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Ping
func Ping(): boolThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Exec
func Exec(_sql: str): intThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Query
func Query(sql: str): dyn db.RowsThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Begin
func Begin(): dyn db.TxThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
LastInsertId
func LastInsertId(): i64The example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Changes
func Changes(): i64The example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Error
func Error(): strThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Quote
func Quote(s: str): strThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Close
func Close(): intThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Txn
struct TxnDatabase.Begin returns. Elasticsearch has no transactions, so every call fails.| Name | Type | Description |
|---|---|---|
handle | void* | The internal state pointer. |
The example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Ok
func Ok(): boolThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Exec
func Exec(_sql: str): intThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Query
func Query(_sql: str): dyn db.RowsThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Commit
func Commit(): intThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Rollback
func Rollback(): intThe 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"http://localhost:9200.The example for this item is shown with the ones above: db-elasticsearch-Client.salam
DEFAULT_PORT
const DEFAULT_PORT: i32 = 9200The example for this item is shown with the ones above: db-elasticsearch-Client.salam
DEAD_NODE_MS
const DEAD_NODE_MS: i32 = 60000The 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(): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
MatchNone
func MatchNone(): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
Match
func Match(field: str, text: str): strmatch query.The example for this item is shown with the ones above: db-elasticsearch-Search.salam
MatchAnd
func MatchAnd(field: str, text: str): strmatch 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): strmatch 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): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
MatchPhrasePrefix
func MatchPhrasePrefix(field: str, text: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
MultiMatch
func MultiMatch(text: str, fields: Vector<str>): strmatch 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): strterm query.The example for this item is shown with the ones above: db-elasticsearch-Search.salam
TermInt
func TermInt(field: str, value: i64): strterm 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): strterm 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>): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
Range
func Range(field: str, low: str, high: str): strrange 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): strrange 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): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
Prefix
func Prefix(field: str, value: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
Wildcard
func Wildcard(field: str, pattern: str): str* and ?.The example for this item is shown with the ones above: db-elasticsearch-Search.salam
Regexp
func Regexp(field: str, pattern: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
Fuzzy
func Fuzzy(field: str, value: str): strfuzzy term query.The example for this item is shown with the ones above: db-elasticsearch-Search.salam
Ids
func Ids(ids: Vector<str>): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
QueryString
func QueryString(query: str): strquery_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>): strsimple_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>): strbool 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>): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
Or
func Or(clauses: Vector<str>): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
Not
func Not(clause: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
Filtered
func Filtered(query: str, filters: Vector<str>): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
ConstantScore
func ConstantScore(filter: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
Nested
func Nested(path: str, query: str): strThe 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): str10km, 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): strSearchRequest.knn.The example for this item is shown with the ones above: db-elasticsearch-Search.salam
SortAsc
func SortAsc(field: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
SortDesc
func SortDesc(field: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
Highlight
func Highlight(fields: Vector<str>): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
TermsAgg
func TermsAgg(field: str, size: int): strterms bucket aggregation, the top values of a field.The example for this item is shown with the ones above: db-elasticsearch-Search.salam
AvgAgg
func AvgAgg(field: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
SumAgg
func SumAgg(field: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
MinAgg
func MinAgg(field: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
MaxAgg
func MaxAgg(field: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
ValueCountAgg
func ValueCountAgg(field: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
CardinalityAgg
func CardinalityAgg(field: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
StatsAgg
func StatsAgg(field: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
HistogramAgg
func HistogramAgg(field: str, interval: f64): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
DateHistogramAgg
func DateHistogramAgg(field: str, calendar_interval: str): strday or month.The example for this item is shown with the ones above: db-elasticsearch-Search.salam
FilterAgg
func FilterAgg(query: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
TopHitsAgg
func TopHitsAgg(size: int): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
AddAgg
func AddAgg(aggs: str, name: str, agg: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
SubAggs
func SubAggs(agg: str, aggs: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
AddMember
func AddMember(obj: str, key: str, raw: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
SearchBody
func SearchBody(req: SearchRequest): strSearchRequest.The example for this item is shown with the ones above: db-elasticsearch-Search.salam
NewBulk
func NewBulk(): BulkThe example for this item is shown with the ones above: db-elasticsearch-Bulk.salam
BulkIndex
func BulkIndex(b &: Bulk, index: str, id: str, doc: str)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)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)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)The example for this item is shown with the ones above: db-elasticsearch-Bulk.salam
BulkDelete
func BulkDelete(b &: Bulk, index: str, id: str)The example for this item is shown with the ones above: db-elasticsearch-Bulk.salam
BulkLen
func BulkLen(b: Bulk): intThe example for this item is shown with the ones above: db-elasticsearch-Bulk.salam
BulkBody
func BulkBody(b: Bulk): strThe example for this item is shown with the ones above: db-elasticsearch-Bulk.salam
BulkReset
func BulkReset(b &: Bulk)The example for this item is shown with the ones above: db-elasticsearch-Bulk.salam
ParseBulkResult
func ParseBulkResult(body: str): BulkResultThe example for this item is shown with the ones above: db-elasticsearch-Bulk.salam
RunBulk
func RunBulk(c: Client, b: Bulk): BulkResultok 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): BulkResultRunBulk 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
Ping
func Ping(c: Client): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
GetInfo
func GetInfo(c: Client): Infodistribution is opensearch on OpenSearch.The example for this item is shown with the ones above: db-elasticsearch-Client.salam
ClusterHealth
func ClusterHealth(c: Client): HealthThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
WaitForStatus
func WaitForStatus(c: Client, status: str, timeout: str): Healthyellow, 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): strThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
NodesInfo
func NodesInfo(c: Client): strThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
CatIndices
func CatIndices(c: Client, pattern: str): Vector<IndexInfo>The example for this item is shown with the ones above: db-elasticsearch-Client.salam
CreateIndex
func CreateIndex(c: Client, index: str, body: str): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
DeleteIndex
func DeleteIndex(c: Client, index: str): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
IndexExists
func IndexExists(c: Client, index: str): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
GetIndex
func GetIndex(c: Client, index: str): strThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
GetMapping
func GetMapping(c: Client, index: str): strThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
PutMapping
func PutMapping(c: Client, index: str, body: str): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
GetSettings
func GetSettings(c: Client, index: str): strThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
PutSettings
func PutSettings(c: Client, index: str, body: str): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
Refresh
func Refresh(c: Client, index: str): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
Flush
func Flush(c: Client, index: str): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
ForceMerge
func ForceMerge(c: Client, index: str, max_segments: int): boolmax_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): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
CloseIndex
func CloseIndex(c: Client, index: str): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
PutAlias
func PutAlias(c: Client, index: str, alias: str): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
DeleteAlias
func DeleteAlias(c: Client, index: str, alias: str): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
AliasExists
func AliasExists(c: Client, alias: str): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
GetAlias
func GetAlias(c: Client, alias: str): Vector<str>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): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
UpdateAliases
func UpdateAliases(c: Client, actions: str): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
PutIndexTemplate
func PutIndexTemplate(c: Client, name: str, body: str): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
DeleteIndexTemplate
func DeleteIndexTemplate(c: Client, name: str): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
IndexTemplateExists
func IndexTemplateExists(c: Client, name: str): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
Reindex
func Reindex(c: Client, source: str, dest: str): i64The 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 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): WriteResultid.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): WriteResultIndex 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): WriteResultThe 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): WriteResultCreate 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): Documentfound 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): DocumentGet 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_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): boolThe 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): WriteResultThe 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): WriteResultUpdate 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): WriteResultThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
Script
func Script(source: str, params: str): strThe 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): WriteResultThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
Delete
func Delete(c: Client, index: str, id: str): WriteResultThe 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): WriteResultDelete 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>The example for this item is shown with the ones above: db-elasticsearch-Client.salam
Count
func Count(c: Client, index: str, query: str): i64The example for this item is shown with the ones above: db-elasticsearch-Client.salam
DefaultConfig
func DefaultConfig(): ConfigDEFAULT_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): Clienthttps://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): ClientThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
ConnectAuth
func ConnectAuth(url: str, username: str, password: str): ClientThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
ConnectApiKey
func ConnectApiKey(url: str, api_key: str): Clientid: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): ClientThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
Ok
func Ok(c: Client): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
Error
func Error(c: Client): strThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
ErrorType
func ErrorType(c: Client): strerror.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): strerror.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): intThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
Nodes
func Nodes(c: Client): Vector<str>The example for this item is shown with the ones above: db-elasticsearch-Client.salam
AuthHeader
func AuthHeader(c: Client): strAuthorization 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): strThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
Close
func Close(c &: Client)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): ResponseThe 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): ResponsePerform, 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): strelasticsearch 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): boolThe example for this item is shown with the ones above: db-elasticsearch-Client.salam
EncodeBasic
func EncodeBasic(username: str, password: str): struser: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): SearchResultPerform.The example for this item is shown with the ones above: db-elasticsearch-Search.salam
Search
func Search(c: Client, index: str, req: SearchRequest): SearchResultThe 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): SearchResultsize 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): SearchResultThe 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): SearchResultScroll 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): SearchResultThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
ClearScroll
func ClearScroll(c: Client, scroll_id: str): boolThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
OpenPit
func OpenPit(c: Client, index: str, keep_alive: str): strsearch_after.The example for this item is shown with the ones above: db-elasticsearch-Search.salam
ClosePit
func ClosePit(c: Client, pit_id: str): boolThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
DeleteByQuery
func DeleteByQuery(c: Client, index: str, query: str): i64The 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): i64DeleteByQuery 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): i64The 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): i64UpdateByQuery 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>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): f64value 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 example for this item is shown with the ones above: db-elasticsearch-Search.salam
AggValue
func AggValue(res: SearchResult, name: str): f64value 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 example for this item is shown with the ones above: db-elasticsearch-Search.salam
AggRaw
func AggRaw(res: SearchResult, name: str): strThe example for this item is shown with the ones above: db-elasticsearch-Search.salam
Sql
func Sql(c: Client, query: str): SqlRowsThe 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? 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): strThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
SqlTranslate
func SqlTranslate(c: Client, query: str): strThe example for this item is shown with the ones above: db-elasticsearch-Sql.salam
Conn
func Conn(c: Client): dyn db.Connectiondb.Connection. Closing it closes the client.The example for this item is shown with the ones above: db-elasticsearch-Sql.salam