Skip to content

Commit

Permalink
check unsupported parameters top_hits
Browse files Browse the repository at this point in the history
  • Loading branch information
PSeitz committed Apr 9, 2024
1 parent 1e9fc51 commit d0aa9e2
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/aggregation/metric/top_hits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::aggregation::intermediate_agg_result::{
IntermediateAggregationResult, IntermediateMetricResult,
};
use crate::aggregation::segment_agg_result::SegmentAggregationCollector;
use crate::aggregation::AggregationError;
use crate::collector::TopNComputer;
use crate::schema::term::JSON_PATH_SEGMENT_SEP_STR;
use crate::schema::OwnedValue;
Expand Down Expand Up @@ -96,6 +97,14 @@ pub struct TopHitsAggregation {
#[serde(rename = "docvalue_fields")]
#[serde(default)]
doc_value_fields: Vec<String>,

// Not supported
_source: Option<serde_json::Value>,
fields: Option<serde_json::Value>,
script_fields: Option<serde_json::Value>,
highlight: Option<serde_json::Value>,
explain: Option<serde_json::Value>,
version: Option<serde_json::Value>,
}

#[derive(Debug, Clone, PartialEq, Default)]
Expand Down Expand Up @@ -148,6 +157,42 @@ impl TopHitsAggregation {
&mut self,
reader: &ColumnarReader,
) -> crate::Result<()> {
let use_doc_value_fields_err = |parameter: &str| {
Err(crate::TantivyError::AggregationError(
AggregationError::InvalidRequest(format!(
"The `{}` parameter is not supported, only `docvalue_fields` is supported in \
`top_hits` aggregation",
parameter
)),
))
};
if self._source.is_some() {
use_doc_value_fields_err("_source")?;
}
if self.fields.is_some() {
use_doc_value_fields_err("fields")?;
}
if self.script_fields.is_some() {
use_doc_value_fields_err("script_fields")?;
}
let unsupported_err = |parameter: &str| {
Err(crate::TantivyError::AggregationError(
AggregationError::InvalidRequest(format!(
"The `{}` parameter is not supported in the `top_hits` aggregation",
parameter
)),
))
};
if self.explain.is_some() {
unsupported_err("explain")?;
}
if self.highlight.is_some() {
unsupported_err("highlight")?;
}
if self.version.is_some() {
unsupported_err("version")?;
}

self.doc_value_fields = self
.doc_value_fields
.iter()
Expand Down

0 comments on commit d0aa9e2

Please sign in to comment.