Elasticsearch

Elasticsearch client for Rust

This is an example for interact to Elasticsearch in Rust.

Image for post
Image for post
Photo by Guilherme Stecanella on Unsplash

Cargo.toml

[package]
name = "rust-getstarted"
version = "0.1.0"
authors = ["cuongld2 <ledinhcuong99@gmail.com>"]
edition = "2018"
reqwest = "0.10.8"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0", features = ["derive"] }
reqwest = { version = "0.10", features = ["json"] }
tokio = { version = "0.2", features = ["full"] }
hyper = "0.13.5"
error-chain = "0.12.4"
elastic = "*"
elastic_derive = "*"
elasticsearch = "7.9.0-alpha.1"
http = "*"
serde_json = "*"
futures = "*"

ElasticSearch query data

Image for post
Image for post
Postman query data from elasticsearch

main.rs

Running this will print these to console

Ok(Response { method: Post, url: "http://localhost:9200/testing/_search", status_code: 200, headers: {"content-type": "application/json; charset=UTF-8"} })

That’s it.

Hope it helps guys.

~~PEACE~~

Written by

A passionate automation engineer who strongly believes in “A man can do anything he wants if he puts in the work”.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store