ongr/elasticsearch-bundle

Symfony 的 Elasticsearch 插件。

安装次数: 1,088,561

依赖者: 22

建议者: 1

安全性: 0

星标: 313

关注者: 31

分支: 189

开放性问题: 68

类型:symfony-bundle

v7.1.0 2023-02-15 13:25 UTC

README

Build Status Latest Stable Version codecov Total Downloads Scrutinizer Code Quality

为了满足专业 Elasticsearch 集成到企业级 Symfony 应用程序的需求,创建了 Elasticsearch Bundle。此插件

  • 使用官方的 elasticsearch-php 客户端。
  • 确保完全集成到 Symfony 框架和 Symfony Flex。

技术亮点

  • 提供了一种表示所有 ElasticSearch 端点的目标化 DSL 查询构建器。
  • 通过 CLI 命令(ongr:es:document:generate)提供交互式文档对象生成器。
  • 提供多个查询结果迭代器,方便您处理结果。
  • 提供索引管理和数据导入/导出/重索引的 CLI 命令。
  • 集成到 Symfony 调试栏中的分析器,显示所有执行的查询。
  • 以可扩展的方式设计,以满足您的所有自定义需求。
  • 支持 Symfony FLEX。
  • 如果您需要帮助,Stack Overflow 是获取答案的首选方式。这是询问关于 ONGR 插件和库问题的首选和推荐方式。

如果您喜欢这个库,请通过买一杯咖啡来帮助我开发它

版本矩阵

Buy Me A Coffee

文档

在线文档

该插件的在线文档可以在 http://docs.ongr.io 找到。文档源存储在代码仓库中的 Resources/doc/ 目录下,所以如果您发现错别字或某些不准确之处,请提交 PR 或至少提交一个 issue 来修复它!

有关对文档的贡献,您可以在 contribute 主题中找到。

常见问题解答

设置插件

步骤 1: 安装 Elasticsearch 插件

Elasticsearch 插件使用 Composer 安装。

php composer.phar require ongr/elasticsearch-bundle "~6.0"

有关安装和部署 Elasticsearch 的说明,请参阅 Elasticsearch 安装页面

在您的 AppKernel 中启用 ElasticSearch 插件

<?php
// config/bundles.php

return [
    // ...
    ONGR\ElasticsearchBundle\ONGRElasticsearchBundle::class => ['all' => true],
];

(可选)步骤 2: 添加配置

添加 Elasticsearch 插件的最小配置。

# config/packages/ongr_elasticsearch.yaml
ongr_elasticsearch:
    analysis:
        filter:
            edge_ngram_filter: #-> your custom filter name to use in the analyzer below
                type: edge_ngram 
                min_gram: 1
                max_gram: 20
        analyzer:
            eNgramAnalyzer: #-> analyzer name to use in the document field
                type: custom
                tokenizer: standard
                filter:
                    - lowercase
                    - edge_ngram_filter #that's the filter defined earlier
    indexes:
        App\Document\Product:
            hosts: [elasticsearch:9200] # optional, the default is 127.0.0.1:9200

这是一个非常基本的示例,有关更多信息,请参阅 配置章节

步骤 3: 定义 Elasticsearch 类型为 Document 对象

此插件使用对象来表示 Elasticsearch 文档。让我们为 products 索引创建一个 Product 类。

// src/Document/Product.php

namespace App\Document;

use ONGR\ElasticsearchBundle\Annotation as ES;

/**
 * //alias and default parameters in the annotation are optional. 
 * @ES\Index(alias="products", default=true)
 */
class Product
{
    /**
     * @ES\Id()
     */
    public $id;

    /**
     * @ES\Property(type="text", analyzer="eNgramAnalyzer")
     */
    public $title;

    /**
     * @ES\Property(type="float")
     */
    public $price;
}

这是一个基本的示例,有关映射的更多信息,请参阅 映射章节

步骤 4: 创建索引和映射

Elasticsearch 插件提供了一些 CLI 命令。其中之一是用于创建索引,在终端中运行以下命令:

bin/console ongr:es:index:create

现在应该使用您文档中的字段创建products索引。

关于其他命令的更多信息,可以在命令章节中找到。

步骤 5:享受 Elasticsearch 的乐趣

Elasticsearch 扩展的完整文档可在此处找到。希望您能用它创造出令人惊叹的东西 😎。

请注意,扩展包文档更新到 6.0 版本的过程仍在进行中。阅读已更新的配置CRUD部分,这将允许您使用扩展包的基本功能。我们将尽快更新其余的文档。

故障排除

许可证

此扩展包根据MIT许可证授权。请参阅扩展包中的完整LICENSE文件。