|
| 1 | +// Copyright 2021-Present Datadog, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +use elasticsearch_dsl::{ClusterStatistics, HitsMetadata, ShardStatistics, Suggest}; |
| 16 | +use quickwit_search::AggregationResults; |
| 17 | +use serde::Serialize; |
| 18 | + |
| 19 | +type Map<K, V> = std::collections::BTreeMap<K, V>; |
| 20 | + |
| 21 | +/// Search response |
| 22 | +/// |
| 23 | +/// This is a fork of [`elasticsearch_dsl::SearchResponse`] with the |
| 24 | +/// `aggregations` field using [`AggregationResults`] instead of |
| 25 | +/// [`serde_json::Value`]. |
| 26 | +#[derive(Debug, Default, Serialize, PartialEq)] |
| 27 | +pub struct ElasticsearchResponse { |
| 28 | + /// The time that it took Elasticsearch to process the query |
| 29 | + pub took: u32, |
| 30 | + |
| 31 | + /// The search has been cancelled and results are partial |
| 32 | + pub timed_out: bool, |
| 33 | + |
| 34 | + /// Indicates if search has been terminated early |
| 35 | + #[serde(default)] |
| 36 | + pub terminated_early: Option<bool>, |
| 37 | + |
| 38 | + /// Scroll Id |
| 39 | + #[serde(skip_serializing_if = "Option::is_none")] |
| 40 | + #[serde(rename = "_scroll_id")] |
| 41 | + pub scroll_id: Option<String>, |
| 42 | + |
| 43 | + /// Dynamically fetched fields |
| 44 | + #[serde(default)] |
| 45 | + pub fields: Map<String, serde_json::Value>, |
| 46 | + |
| 47 | + /// Point in time Id |
| 48 | + #[serde(skip_serializing_if = "Option::is_none")] |
| 49 | + pub pit_id: Option<String>, |
| 50 | + |
| 51 | + /// Number of reduce phases |
| 52 | + #[serde(skip_serializing_if = "Option::is_none")] |
| 53 | + pub num_reduce_phases: Option<u64>, |
| 54 | + |
| 55 | + /// Maximum document score. [None] when documents are implicitly sorted |
| 56 | + /// by a field other than `_score` |
| 57 | + #[serde(skip_serializing_if = "Option::is_none")] |
| 58 | + pub max_score: Option<f32>, |
| 59 | + |
| 60 | + /// Number of clusters touched with their states |
| 61 | + #[serde(skip_serializing_if = "Option::is_none", rename = "_clusters")] |
| 62 | + pub clusters: Option<ClusterStatistics>, |
| 63 | + |
| 64 | + /// Number of shards touched with their states |
| 65 | + #[serde(rename = "_shards")] |
| 66 | + pub shards: ShardStatistics, |
| 67 | + |
| 68 | + /// Search hits |
| 69 | + pub hits: HitsMetadata, |
| 70 | + |
| 71 | + /// Search aggregations |
| 72 | + #[serde(skip_serializing_if = "Option::is_none")] |
| 73 | + pub aggregations: Option<AggregationResults>, |
| 74 | + |
| 75 | + #[serde(skip_serializing_if = "Map::is_empty", default)] |
| 76 | + /// Suggest response |
| 77 | + pub suggest: Map<String, Vec<Suggest>>, |
| 78 | +} |
0 commit comments