actix-elastic

Crates.ioactix-elastic
lib.rsactix-elastic
version1.0.7
sourcesrc
created_at2020-10-11 10:40:11.304255
updated_at2020-12-06 15:44:14.286102
descriptionelasticsearch 7.x actix actor
homepage
repositoryhttps://github.com/GopherJ/actix-elastic
max_upload_size
id298304
size38,029
Cheng JIANG (GopherJ)

documentation

README

actix-elastic

Installation

Add this package to Cargo.toml of your project. (Check https://crates.io/crates/actix-elastic for right version)

[dependencies]
actix = "0.10.0"
actix-elastic = "1.0.0"

Get started

  1. Create an elastic actix actor
use actix::{Arbiter, Addr, Supervisor};
use actix_elastic::{EsClient, EsCmd, EsResult};

let arb = Arbiter::new();
let elastic_url = "http://127.0.0.1:9200"

let addr: Addr<EsClient<CustomType>> = Supervisor::start_in_arbiter(&arb, move |_| EsClient::new(elastic_url).unwrap());
  1. Send elastic command
use serde_json::json;

addr.send(EsCmd::Index("example_index_1", ("id_1", CustomType))).await??;

addr.send(EsCmd::Search("example_index_1", json!({
    "query": {
        "match_all": {}
    }
})).await??;

addr.send(EsCmd::DeleteByQuery("example_index_1", json!({
    "query": {
        "bool": {
            "must": [
                {
                    "match_phase": {
                        "name": "alice"
                    }
                }
            ]
        }
    }
}))).await??;
  1. Scroll All Hits And Give Every Chunk To Client
use actix_web::HttpResponse;

match addr.send(EsCmd::ScrollBytes("example_index_1", json!({
    "query": {
        "match_all": {}
    }
}))).await?? {
    EsResult::ScrollBytes(stream) => Ok(HttpResponse::Ok().content_type("application/json").streaming_response(stream)),
        _ => unreachable!()
}
  1. Scroll Deserialized Items

match addr.send(EsCmd::ScrollItems("example_index_1", json!({
    "query": {
        "match_all": {}
    }
}))).await?? {
    EsResult::ScrollItems(mut stream) => {
        while let Some(hits) = stream.next().await {
            println!("{:?}", hits.len());
        }
    },
        _ => unreachable!()
}
Commit count: 10

cargo fmt