Crate opensearch_dsl

Source
Expand description

§Strongly typed OpenSearch DSL written in Rust

This is an unofficial library and doesn’t yet support all the DSL, it’s still work in progress.

§Features

  • Strongly typed queries
  • Strongly typed aggregations
  • Automatically skips empty queries making DSL pleasant to use
  • Crate doesn’t depend on opensearch-rs and can be used as a standalone library with any HTTP client to call OpenSearch

§Installation

Add opensearch-dsl crate and version to Cargo.toml

[dependencies]
opensearch-dsl = "0.2"

§Documentation

Documentation for the library is available on docs.rs

§Quick start

use opensearch_dsl::*;

fn main() {
  let query = Search::new()
    .source(false)
    .stats("statistics")
    .from(0)
    .size(30)
    .query(
      Query::bool()
        .must(Query::multi_match(
          ["title", "description"],
          "you know, for search",
        ))
        .filter(Query::terms("tags", ["opensearch"]))
        .should(Query::term("verified", true).boost(10)),
    )
    .aggregate(
      "country_ids",
      Aggregation::terms("country_id")
        .aggregate("catalog_ids", Aggregation::terms("catalog_id"))
        .aggregate("company_ids", Aggregation::terms("company_id"))
        .aggregate(
          "top1",
          Aggregation::top_hits()
            .size(1)
            .sort(FieldSort::ascending("user_id")),
        ),
    )
    .rescore(Rescore::new(Query::term("field", 1)).query_weight(1.2));
}

See examples for more.

§License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Re-exports§

pub use self::analyze::*;
pub use self::search::*;

Modules§

analyze
Performs analysis on a text string and returns the resulting tokens.
search
Search APIs are used to search and aggregate data stored in OpenSearch indices and data streams. For an overview and related tutorials, see Search your data.