0

I have created my own customised FacetedSearch class using Pythons Elasticsearch DSL library to perform search with additional filtering in def search(self). Now I would like to reuse my class to do some statistical aggregations. To stay DRY I want to reuse this class and for performance reason I would like to temporarily disable facets calculation when they are not necessary while preserving all the filtering. So question is how can I temporarily omit facets in FacetedSearch search?

igo
  • 6,359
  • 6
  • 42
  • 51

1 Answers1

1

So you just want to use the Search object's query, but not it's aggregations? In that case just call the object's search() method to get the Search object and go from there.

If you want the aggregations, but just want to skip the python-level facets calculation just use the build_search method to get the raw Search object including the aggregations.

Honza Král
  • 2,982
  • 14
  • 11
  • Thanks! Furthermore I realised that I need to use standard filter instead of build-in post_filter so I created my own `build_search` function that skips `self.aggregate()` and use different `self.filter(s)`. Is there any reason why `self.build_search()` is automatically run from `__init__`? It's useless in my case. – igo Feb 21 '17 at 12:40
  • The reason why it's run from `__init__` is because it is always needed so it makes sense to run it there instead fo trying to create some form of property that would create it on demand. – Honza Král Feb 21 '17 at 13:26