在上一章中,我们看到了如何使用原生客户端通过 Java 访问 Elasticsearch 服务器。本章专门介绍 Python 语言以及如何通过其客户端管理常见任务。
除了 Java,Elasticsearch 团队还支持 Perl、PHP、Python、.NET 和 Ruby 的官方客户端(请参阅 Elasticsearch 博客上的公告帖子,网址为 http://www.elasticsearch.org/blog/unleash-the-clients-ruby-python-php-perl/)。与其他实现相比,这些客户端具有很多优势。以下列表中给出了其中一些:
- They are strongly tied to the Elasticsearch API. These clients are direct translations of the native Elasticsearch REST interface—the Elasticsearch team.
- They handle dynamic node detection and failovers. They are built with a strong networking base for communicating with the cluster.
- They have full coverage of the REST API. They share the same application approach for every language in which they are available, so switching from one language to another is fast.
- They are easily extensible.
Python 客户端与其他 Python 框架(例如 Django、web2py 和 Pyramid)配合得非常好。它允许非常快速地访问文档、索引和集群。
在本章中,我将尝试描述 Elasticsearch 官方 Python 客户端最重要的功能;对于其他示例,我建议您查看 https://github.com/elastic/elasticsearch 上的在线 GitHub 存储库和文档-py 和相关文档位于 https://elasticsearch-py.readthedocs.io/en/master/< /一>。
在本章中,我们将介绍以下食谱:
- Creating a client
- Managing indices
- Managing mappings
- Managing documents
- Executing a standard search
- Executing a search with aggregations