Replication es.search (index_results.execute()) for es.scroll

99封情书 提交于 2020-02-07 05:35:49

问题


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:


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!



来源:https://stackoverflow.com/questions/52447844/replication-es-search-index-results-execute-for-es-scroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!