API
#github.com/xulang-org/packages/elasticsearch
Xu 0.8.8 API
import: elasticsearch #github.com/xulang-org/packages/elasticsearch
counts: 4 fns, 25 methods, 5 types, 0 consts, 0 ifaces
Elasticsearch / OpenSearch driver package for Xu. Features Compatible with Elasticsearch 7.x/8.x and OpenSearch 1.x/2.x. Pure HTTP REST communication via Xu standard library. Full index lifecycle: create, delete, check exists, refresh. Full document CRUD: index, get, update, delete. Search Query DSL support with total hit count tracking.
github.com/xulang-org/packages · 0.1.1 · Install and use
open
pub fn open(endpoint string) Client
Purpose
Elasticsearch / OpenSearch driver package for Xu. Features Compatible with Elasticsearch 7.x/8.x and OpenSearch 1.x/2.x. Pure HTTP REST communication via Xu standard library. Full index lifecycle: create, delete, check exists, refresh. Full document CRUD: index, get, update, delete. Search Query DSL support with total hit count tracking.
Parameters
endpoint string- endpoint (string)
Returns
Client — a value of this type
open_pool
pub fn open_pool(endpoint string, max_idle int) Pool
Purpose
Open pool.
Parameters
endpoint string- endpoint (string)
max_idle int- max_idle (int)
Returns
Pool — a value of this type
struct Response
pub struct Response {
pub status_code int
pub body string
}
Purpose
Public struct `Response`.
Parameters
status_code int- field (int)
body string- body
struct Client
pub struct Client {
pub host string
pub port int
}
Purpose
Public struct `Client`.
Parameters
host string- host
port int- port
new_client
pub fn new_client(endpoint string) Client
Purpose
Construct client.
Parameters
endpoint string- endpoint (string)
Returns
Client — a value of this type
(&mut Client) request
pub fn (c &mut Client) request(method string, path string, body string) Response
Purpose
Call `request` on `&mut Client`. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
method string- method (string)
path string- filesystem path (string)
body string- body (string)
Returns
Response — a value of this type
(&mut Client) ping
pub fn (c &mut Client) ping() bool
Purpose
Call `ping` on `&mut Client`.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
Returns
bool — true or false
(&mut Client) info
pub fn (c &mut Client) info() string
Purpose
Call `info` on `&mut Client`. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
Returns
string — result string
(&mut Client) index_doc
pub fn (c &mut Client) index_doc(index string, id string, doc_json string) string
Purpose
Method on `&mut Client`: index doc. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
index string- index (string)
id string- id (string)
doc_json string- doc_json (string)
Returns
string — result string
(&mut Client) get_doc
pub fn (c &mut Client) get_doc(index string, id string) string
Purpose
Method on `&mut Client`: read doc. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
index string- index (string)
id string- id (string)
Returns
string — result string
(&mut Client) delete_doc
pub fn (c &mut Client) delete_doc(index string, id string) bool
Purpose
Method on `&mut Client`: delete doc. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
index string- index (string)
id string- id (string)
Returns
bool — true or false
(&mut Client) update_doc
pub fn (c &mut Client) update_doc(index string, id string, doc_json string) bool
Purpose
Method on `&mut Client`: update doc. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
index string- index (string)
id string- id (string)
doc_json string- doc_json (string)
Returns
bool — true or false
(&mut Client) create_index
pub fn (c &mut Client) create_index(index string, mapping_json string) bool
Purpose
Method on `&mut Client`: create index. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
index string- index (string)
mapping_json string- mapping_json (string)
Returns
bool — true or false
(&mut Client) delete_index
pub fn (c &mut Client) delete_index(index string) bool
Purpose
Method on `&mut Client`: delete index. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
index string- index (string)
Returns
bool — true or false
(&mut Client) index_exists
pub fn (c &mut Client) index_exists(index string) bool
Purpose
Method on `&mut Client`: index exists.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
index string- index (string)
Returns
bool — true or false
(&mut Client) refresh
pub fn (c &mut Client) refresh(index string) bool
Purpose
Call `refresh` on `&mut Client`. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
index string- index (string)
Returns
bool — true or false
struct Pool
pub struct Pool {
pub host string
pub port int
pub endpoint string
pub state chan pool.State
pub max_idle int
}
Purpose
Connection Pool for Elasticsearch & OpenSearch. Manages reusable TCP/HTTP socket connections.
Parameters
host string- host
port int- port
endpoint string- field (string)
state chan pool.State- field (channel; type chan pool.State)
max_idle int- field (int)
new_pool
pub fn new_pool(endpoint string, max_idle int) Pool
Purpose
Construct pool.
Parameters
endpoint string- endpoint (string)
max_idle int- max_idle (int)
Returns
Pool — a value of this type
(&Pool) get
pub fn (p &Pool) get() Client
Purpose
Call `get` on `&Pool`.
Parameters
p &Pool- receiver &Pool (borrow)
Returns
Client — a value of this type
(&Pool) dup
pub fn (p &Pool) dup() Pool
Purpose
Shares sockets and close state; clones configuration strings.
Parameters
p &Pool- receiver &Pool (borrow)
Returns
Pool — a value of this type
(&Pool) get_conn
pub fn (p &Pool) get_conn() int
Purpose
Method on `&Pool`: read conn.
Parameters
p &Pool- receiver &Pool (borrow)
Returns
int — a value of this type
(&Pool) put_conn
pub fn (p &Pool) put_conn(fd int)
Purpose
Method on `&Pool`: put connection.
Parameters
p &Pool- receiver &Pool (borrow)
fd int- file descriptor (int)
(&Pool) discard_conn
pub fn (p &Pool) discard_conn(fd int)
Purpose
Method on `&Pool`: discard connection.
Parameters
p &Pool- receiver &Pool (borrow)
fd int- file descriptor (int)
(&Pool) search
pub fn (p &Pool) search(index string, query_dsl string) SearchResult
Purpose
Method on `&Pool`: binary search. Throws on failure.
Parameters
p &Pool- receiver &Pool (borrow)
index string- index (string)
query_dsl string- query_dsl (string)
Returns
SearchResult — a value of this type
(&Pool) search_match
pub fn (p &Pool) search_match(index string, field string, query_text string) SearchResult
Purpose
Method on `&Pool`: binary search match. Throws on failure.
Parameters
p &Pool- receiver &Pool (borrow)
index string- index (string)
field string- field (string)
query_text string- query_text (string)
Returns
SearchResult — a value of this type
(&Pool) get_doc
pub fn (p &Pool) get_doc(index string, id string) string
Purpose
Method on `&Pool`: read doc. Throws on failure.
Parameters
p &Pool- receiver &Pool (borrow)
index string- index (string)
id string- id (string)
Returns
string — result string
(&Pool) index_doc
pub fn (p &Pool) index_doc(index string, id string, doc_json string) string
Purpose
Method on `&Pool`: index doc. Throws on failure.
Parameters
p &Pool- receiver &Pool (borrow)
index string- index (string)
id string- id (string)
doc_json string- doc_json (string)
Returns
string — result string
(&Pool) delete_doc
pub fn (p &Pool) delete_doc(index string, id string) bool
Purpose
Method on `&Pool`: delete doc. Throws on failure.
Parameters
p &Pool- receiver &Pool (borrow)
index string- index (string)
id string- id (string)
Returns
bool — true or false
(&Pool) ping
pub fn (p &Pool) ping() bool
Purpose
Call `ping` on `&Pool`.
Parameters
p &Pool- receiver &Pool (borrow)
Returns
bool — true or false
(&Pool) close
Purpose
Method on `&Pool`: close the resource.
Parameters
p &Pool- receiver &Pool (borrow)
struct SearchHit
pub struct SearchHit {
pub id string
pub score string
pub source string
}
Purpose
Public struct `SearchHit`.
Parameters
id string- field (string)
score string- field (string)
source string- field (string)
struct SearchResult
pub struct SearchResult {
pub total int
pub raw_json string
pub hits []SearchHit
}
Purpose
Public struct `SearchResult`.
Parameters
total int- field (int)
raw_json string- field (string)
hits []SearchHit- field ([]SearchHit)
(&mut Client) search
pub fn (c &mut Client) search(index string, query_dsl string) SearchResult
Purpose
Method on `&mut Client`: binary search. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
index string- index (string)
query_dsl string- query_dsl (string)
Returns
SearchResult — a value of this type
(&mut Client) search_match
pub fn (c &mut Client) search_match(index string, field string, query_text string) SearchResult
Purpose
Method on `&mut Client`: binary search match. Throws on failure.
Parameters
c &mut Client- receiver &mut Client (exclusive borrow)
index string- index (string)
field string- field (string)
query_text string- query_text (string)
Returns
SearchResult — a value of this type