扩展导入的(第三方模块)

时间:2018-09-22 19:36:42

标签: python-2.7

我正在使用Elasticsearch和Python,并想向一个类添加一个def,以便它像在模块内一样工作

在Elasticsearch中,有一个名为search.py​​的模块,其中包括

class Search(Request):
    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

在我自己的代码中,我想要类似

def execute_added(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.scroll(
                scroll_id="THE_ID"
            )
        )
    return self._response

与使用Elasticsearch dsl中的所有其他功能一样,这就像在search.py​​中编写的那样工作。用于运行代码的所有代码均与Elastic搜索文件一起存储

有可能吗?

这是受到我在这里的问题的启发:Replication es.search (index_results.execute()) for es.scroll

谢谢

0 个答案:

没有答案