elastic / elasticsearch-dsl-py

High level Python client for Elasticsearch
http://elasticsearch-dsl.readthedocs.org
Apache License 2.0
3.83k stars 801 forks source link

Are rollup searches supported? #1637

Open mathijsfr opened 1 year ago

mathijsfr commented 1 year ago

How do I search rollups? The documentation doesn't show anything on rollup searches.

alick97 commented 1 year ago

How do I search rollups? The documentation doesn't show anything on rollup searches.

not found in official, but this hook may run with unknow bug

from elasticsearch_dsl import Search
from elasticsearch_dsl.connections import get_connection
from elasticsearch.client.utils import GLOBAL_PARAMS

class RollupSearch(Search)
    _ALLOW_ROLLUP_SEARCH_PARAM = set(["rest_total_hits_as_int", "typed_keys", *GLOBAL_PARAMS])

    def execute(self, ignore_cache=False):
        """
        Execute the search and return an instance of ``Response`` wrapping all
        the data.

        :arg ignore_cache: if set to ``True``, consecutive calls will hit
            ES, while cached result will be ignored. Defaults to `False`
        """
        if ignore_cache or not hasattr(self, "_response"):
            es = get_connection(self._using)
            es.search()
            self._response = self._response_class(
                self, es.rollup.rollup_search(index=self._index, body=self.to_dict(), **{k:v for k,v in self._params.items() if  k in self._ALLOW_ROLLUP_SEARCH_PARAM})
            )
        return self._response