XU XUv0.8.8
中文

API

#github.com/xulang-org/packages/elasticsearch

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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub struct Client {
    pub host string
    pub port int
}

Purpose

Public struct `Client`.

Parameters

host string
host
port int
port

new_client

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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_match

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
pub fn (p &Pool) ping() bool

Purpose

Call `ping` on `&Pool`.

Parameters

p &Pool
receiver &Pool (borrow)

Returns

bool — true or false

(&Pool) close

XuAPI
pub fn (p &Pool) close()

Purpose

Method on `&Pool`: close the resource.

Parameters

p &Pool
receiver &Pool (borrow)

struct SearchHit

XuAPI
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

XuAPI
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_match

XuAPI
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