All Projects → elastic → Elasticsearch Rs

elastic / Elasticsearch Rs

Licence: apache-2.0
Official Elasticsearch Rust Client

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Elasticsearch Rs

Elasticsearch Php
Official PHP low-level client for Elasticsearch.
Stars: ✭ 4,760 (+1055.34%)
Mutual labels:  elasticsearch, client
Elasticsearch Net
Elasticsearch.Net & NEST
Stars: ✭ 3,181 (+672.09%)
Mutual labels:  elasticsearch, client
Elasticsearch Js
Official Elasticsearch client library for Node.js
Stars: ✭ 4,828 (+1071.84%)
Mutual labels:  elasticsearch, client
Elasticsearch Py
Official Elasticsearch client library for Python
Stars: ✭ 3,486 (+746.12%)
Mutual labels:  elasticsearch, client
Elasticsearch Ruby
Ruby integrations for Elasticsearch
Stars: ✭ 1,848 (+348.54%)
Mutual labels:  elasticsearch, client
Go Elasticsearch
The official Go client for Elasticsearch
Stars: ✭ 3,817 (+826.46%)
Mutual labels:  elasticsearch, client
Graphql Ws
Coherent, zero-dependency, lazy, simple, GraphQL over WebSocket Protocol compliant server and client.
Stars: ✭ 398 (-3.4%)
Mutual labels:  client
Janusgraph
JanusGraph: an open-source, distributed graph database
Stars: ✭ 4,277 (+938.11%)
Mutual labels:  elasticsearch
Ck
Collective Knowledge framework (CK) helps to organize black-box research software as a database of reusable components and micro-services with common APIs, automation actions and extensible meta descriptions. See real-world use cases from Arm, General Motors, ACM, Raspberry Pi foundation and others:
Stars: ✭ 395 (-4.13%)
Mutual labels:  elasticsearch
Node Vault
Client for HashiCorp's Vault
Stars: ✭ 391 (-5.1%)
Mutual labels:  client
Gpmall
【咕泡学院实战项目】-基于SpringBoot+Dubbo构建的电商平台-微服务架构、商城、电商、微服务、高并发、kafka、Elasticsearch
Stars: ✭ 4,241 (+929.37%)
Mutual labels:  elasticsearch
Irc
the irc crate – usable, async IRC for Rust
Stars: ✭ 409 (-0.73%)
Mutual labels:  client
Yakyak
Desktop chat client for Google Hangouts
Stars: ✭ 3,869 (+839.08%)
Mutual labels:  client
Ts3audiobot
Advanced Musicbot for Teamspeak 3
Stars: ✭ 397 (-3.64%)
Mutual labels:  client
Elasticsearch
This repository has been archived.
Stars: ✭ 405 (-1.7%)
Mutual labels:  elasticsearch
Puppet Elasticsearch
Elasticsearch Puppet module
Stars: ✭ 396 (-3.88%)
Mutual labels:  elasticsearch
Canal mysql elasticsearch sync
基于canal的mysql和elasticsearch实时同步方案,支持增量同步和全量同步
Stars: ✭ 410 (-0.49%)
Mutual labels:  elasticsearch
Huejay
Philips Hue client for Node.js
Stars: ✭ 395 (-4.13%)
Mutual labels:  client
Laravel Scout Elastic Demo
笑来搜原型 Laravel Scout & ElasticSearch ik
Stars: ✭ 403 (-2.18%)
Mutual labels:  elasticsearch
Elasticsearch Prometheus Exporter
Prometheus exporter plugin for Elasticsearch
Stars: ✭ 409 (-0.73%)
Mutual labels:  elasticsearch

elasticsearch   Latest Version Docs Apache-2 licensed

Official Rust Client for Elasticsearch.

Full documentation is available at https://docs.rs/elasticsearch

The project is still very much a work in progress and in an alpha state; input and contributions welcome!

Versions and Compatibility

Rust client Elasticsearch Status
7.x 7.x alpha

A major version of the client is compatible with the same major version of Elasticsearch. Since Elasticsearch is developed following Semantic Versioning principles, Any minor/patch version of the client can be used against any minor/patch version of Elasticsearch within the same major version lineage. For example,

  • A 7.5.0 client can be used against 7.0.0 Elasticsearch
  • A 7.5.0 client can be used against 7.6.0 Elasticsearch

In the former case, a 7.5.0 client may contain additional API functions that are not available in 7.0.0 Elasticsearch. In this case, these APIs cannot be used, but for any APIs available in Elasticsearch, the respective API functions on the client will be compatible.

In the latter case, a 7.5.0 client won't contain API functions for APIs that are introduced in Elasticsearch 7.6.0+, but for all other APIs available in Elasticsearch, the respective API functions on the client will be compatible.

No compatibility assurances are given between different major versions of the client and Elasticsearch. Major differences likely exist between major versions of Elasticsearch, particularly around request and response object formats, but also around API urls and behaviour.

Features

The following are a list of Cargo features that can be enabled or disabled:

  • native-tls (enabled by default): Enables TLS functionality provided by native-tls.
  • rustls-tls: Enables TLS functionality provided by rustls.
  • beta-apis: Enables beta APIs. Beta APIs are on track to become stable and permanent features. Use them with caution because it is possible that breaking changes are made to these APIs in a minor version.
  • experimental-apis: Enables experimental APIs. Experimental APIs are just that - an experiment. An experimental API might have breaking changes in any future version, or it might even be removed entirely. This feature also enables beta-apis.

Getting started

The client exposes all Elasticsearch APIs as associated functions, either on the root client, Elasticsearch, or on one of the namespaced clients, such as Cat, Indices, etc. The namespaced clients are based on the grouping of APIs within the Elasticsearch and X-Pack REST API specs from which much of the client is generated. All API functions are async only, and can be awaited.

Installing

Add elasticsearch crate and version to Cargo.toml. Choose the version that is compatible with the version of Elasticsearch you're using

[dependencies]
elasticsearch = "8.0.0-alpha.1"

The following optional dependencies may also be useful to create requests and read responses

serde = "~1"
serde_json = "~1"

Async support with tokio

The client uses reqwest to make HTTP calls, which internally uses the tokio runtime for async support. As such, you may require to take a dependency on tokio in order to use the client. For example, in Cargo.toml, you may need the following dependency,

tokio = { version = "*", features = ["full"] }

and to attribute async main function with #[tokio::main]

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // your code ...
    Ok(())
}

and attribute test functions with #[tokio::test]

#[tokio::test]
async fn my_test() -> Result<(), Box<dyn std::error::Error>> {
    // your code ...
    Ok(())
}

Create a client

Build a transport to make API requests to Elasticsearch using the TransportBuilder, which allows setting of proxies, authentication schemes, certificate validation, and other transport related settings.

To create a client to make API calls to Elasticsearch running on http://localhost:9200

use elasticsearch::Elasticsearch;

fn main() {
    let client = Elasticsearch::default();
}

Alternatively, you can create a client to make API calls against Elasticsearch running on a specific url

use elasticsearch::{
    Elasticsearch, Error, 
    http::transport::Transport
};

fn main() -> Result<(), Error> {
    let transport = Transport::single_node("https://example.com")?;
    let client = Elasticsearch::new(transport);
    Ok(())
}

If you're running against an Elasticsearch deployment in Elastic Cloud, a client can be created using a Cloud ID and credentials retrieved from the Cloud web console

use elasticsearch::{
    auth::Credentials,
    Elasticsearch, Error,
    http::transport::Transport,
};

fn main() -> Result<(), Error> {
    let cloud_id = "cluster_name:Y2xvdWQtZW5kcG9pbnQuZXhhbXBsZSQzZGFkZjgyM2YwNTM4ODQ5N2VhNjg0MjM2ZDkxOGExYQ==";
    // can use other types of Credentials too, like Bearer or ApiKey
    let credentials = Credentials::Basic("<username>".into(), "<password>".into());
    let transport = Transport::cloud(cloud_id, credentials)?;
    let client = Elasticsearch::new(transport);
    Ok(())
}

More control over how a Transport is built can be achieved using TransportBuilder to build a transport, and passing it to Elasticsearch::new() create a new instance of Elasticsearch

use url::Url;
use elasticsearch::{
    Error, Elasticsearch,
    http::transport::{TransportBuilder,SingleNodeConnectionPool},
};

fn main() -> Result<(), Error> {
    let url = Url::parse("https://example.com")?;
    let conn_pool = SingleNodeConnectionPool::new(url);
    let transport = TransportBuilder::new(conn_pool).disable_proxy().build()?;
    let client = Elasticsearch::new(transport);
    Ok(())
}

Making API calls

The following will execute a POST request to /_search?allow_no_indices=true with a JSON body of {"query":{"match_all":{}}}

use elasticsearch::{Elasticsearch, Error, SearchParts};
use serde_json::{json, Value};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Elasticsearch::default();

    // make a search API call
    let search_response = client
        .search(SearchParts::None)
        .body(json!({
            "query": {
                "match_all": {}
            }
        }))
        .allow_no_indices(true)
        .send()
        .await?;

    // get the HTTP response status code
    let status_code = search_response.status_code();

    // read the response body. Consumes search_response
    let response_body = search_response.json::<Value>().await?;

    // read fields from the response body
    let took = response_body["took"].as_i64().unwrap();

    Ok(())
}

The client provides functions on each API builder struct for all query string parameters available for that API. APIs with multiple URI path variants, where some can contain parts parameters, are modelled as enums.

Elasticsearch also has an async send function on the root that allows sending an API call to an endpoint not represented as an API function, for example, experimental and beta APIs

use elasticsearch::{http::Method, Elasticsearch, Error, SearchParts};
use http::HeaderMap;
use serde_json::Value;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Elasticsearch::default();
    let body = b"{\"query\":{\"match_all\":{}}}";
    let response = client
        .send(
            Method::Post,
            SearchParts::Index(&["tweets"]).url().as_ref(),
            HeaderMap::new(),
            Option::<&Value>::None,
            Some(body.as_ref()),
            None,
        )
        .await?;
    Ok(())
}

License

This is free software, licensed under The Apache License Version 2.0..

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].