Replication es.search (index_results.execute()) fo

2019-08-18 03:48发布

I am using the python dsl library

When I do a standard search I use execute(), this is a method that will return a Response object (https://elasticsearch-dsl.readthedocs.io/en/latest/search_dsl.html). Looks to have .search at the heart of it

In some cases I to use scroll . This works, but it returns a dictionary.

What I want to do is use scroll but to return a response in the same way that execute() does

The DSL Elasticsearch function does this

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

    :arg response_class: optional subclass of ``Response`` to use instead.
    """
    if ignore_cache or not hasattr(self, '_response'):
        es = connections.get_connection(self._using)

        self._response = self._response_class(
            self,
            es.search(
                index=self._index,
                doc_type=self._doc_type,
                body=self.to_dict(),
                **self._params
            )
        )
    return self._response

What I need to do (I think) is replicate that but for scroll, so that all the data returned is of the same type.

Any help would be appreciated

Thanks

1条回答
狗以群分
2楼-- · 2019-08-18 04:37

I believe what you are looking for is the scan method on the Search object which return an iterator of the documents using the scan/scroll API under the hood - https://elasticsearch-dsl.readthedocs.io/en/latest/search_dsl.html#pagination

Hope this helps!

查看更多
登录 后发表回答