Skip to content

Commit 3858e53

Browse files
committed
⏪ Revert sampled facet for empty query
1 parent 2a27fa0 commit 3858e53

File tree

2 files changed

+0
-25
lines changed

2 files changed

+0
-25
lines changed

openaleph_search/query/base.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
log = get_logger(__name__)
2929
settings = Settings()
3030

31-
_FACET_SAMPLER_KEY = "facets.sampled"
32-
3331

3432
class Query:
3533
TEXT_FIELDS: ClassVar[list[str]] = [Field.TEXT]
@@ -207,17 +205,6 @@ def get_aggregations(self) -> dict[str, Any]:
207205
else:
208206
aggregations.update(facet_aggregations)
209207

210-
# For empty queries on large indexes, wrap facet aggregations in a
211-
# sampler so ES only aggregates a subset of docs per shard. Gives
212-
# approximate counts but is dramatically faster.
213-
if self.is_empty_query and aggregations:
214-
aggregations = {
215-
_FACET_SAMPLER_KEY: {
216-
"sampler": {"shard_size": settings.facet_sampler_size},
217-
"aggs": aggregations,
218-
}
219-
}
220-
221208
# Significant terms aggregations
222209
for facet_name in self.parser.facet_significant_names:
223210
facet_aggregations = {}
@@ -500,12 +487,4 @@ def search(self) -> ObjectApiResponse:
500487
hits=result.get("hits", {}).get("total", {}).get("value"),
501488
)
502489

503-
# Unwrap sampled facet aggregations so consumers see the same
504-
# response structure regardless of whether sampling was used.
505-
aggs = result.get("aggregations", {})
506-
if _FACET_SAMPLER_KEY in aggs:
507-
sampled = aggs.pop(_FACET_SAMPLER_KEY)
508-
sampled.pop("doc_count", None)
509-
aggs.update(sampled)
510-
511490
return result

openaleph_search/settings.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ class Settings(BaseSettings):
6161
index_boost_documents: int = 1
6262
index_boost_pages: int = 1
6363

64-
# Sampler shard_size for facet aggregations on empty queries.
65-
# Uses approximate counts for faster response on large indexes.
66-
facet_sampler_size: int = 5000
67-
6864
# Sampler for significant_terms / significant_text aggregations
6965
significant_terms_sampler_size: int = 2000
7066
significant_text_sampler_size: int = 200

0 commit comments

Comments
 (0)