Crates.io | elasticsearch-dsl |
lib.rs | elasticsearch-dsl |
version | 0.4.22 |
source | src |
created_at | 2021-10-21 11:26:21.420598 |
updated_at | 2024-08-01 05:10:29.79245 |
description | Strongly typed Elasticsearch DSL |
homepage | |
repository | https://github.com/vinted/elasticsearch-dsl-rs |
max_upload_size | |
id | 468418 |
size | 739,941 |
A high level library, giving a strongly typed DSL that maps one to one with the official Elasticsearch query DSL.
Add elasticsearch-dsl
crate and version to Cargo.toml
[dependencies]
elasticsearch-dsl = "0.4"
Documentation for the library is available on docs.rs
use elasticsearch_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", ["elasticsearch"]))
.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));
}
{
"_source": false,
"stats": ["statistics"],
"from": 0,
"size": 30,
"query": {
"bool": {
"must": [
{
"multi_match": {
"fields": ["title", "description"],
"query": "you know, for search"
}
}
],
"filter": [{ "terms": { "tags": ["elasticsearch"] } }],
"should": [{ "term": { "verified": { "value": true, "boost": 10.0 } } }]
}
},
"aggs": {
"country_ids": {
"terms": { "field": "country_id" },
"aggs": {
"catalog_ids": { "terms": { "field": "catalog_id" } },
"company_ids": { "terms": { "field": "company_id" } },
"top1": {
"top_hits": {
"size": 1,
"sort": [{ "user_id": { "order": "asc" } }]
}
}
}
}
},
"rescore": [
{
"query": {
"rescore_query": { "term": { "field": { "value": 1 } } },
"query_weight": 1.2
}
}
]
}
See examples for more.