blast-project/search-bundle

与 ElasticSearch 结合的搜索系统

安装: 80

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 5

分支: 0

开放问题: 0

类型:symfony-bundle

dev-wip-platform 2018-03-16 13:13 UTC

This package is not auto-updated.

Last update: 2024-09-15 04:42:11 UTC


README

用于处理使用 ElasticSearch 实例的搜索索引的包。

要求

您必须有一个运行良好且配置正确的 ElasticSearch

(可选) 使用 Elastic Stack

使用分发版

sudo apt-get install elasticsearch

通过编辑 /etc/elasticsearch/elasticsearch.yml 来配置您的 ElasticSearch 实例以监听正确的网络接口

network.host: 0.0.0.0 # change 0.0.0.0 with your public IP or 127.0.0.1 for local exposure only
http.port: 9200

使用 Docker

仅用于开发目的,您可以使用完整的 Elastic Stack(以前的 ELK stack)。

为了简单起见,您可以使用该堆栈的 Docker 镜像: https://hub.docker.com/r/sebp/elk/

docker run -p 5601:5601 -p 9200:9200 -p 5044:5044 -it --name elk sebp/elk:611

注意: 由于 ES 6 与 FOSElasticaBundle 不兼容(请参阅此问题 FriendsOfSymfony/FOSElasticaBundle#1267),请不要使用 ElasticSearch 6。

您可以使用自定义 SystemD 服务启动此 Docker 镜像(创建服务文件 /etc/systemd/system/elk.service)。

[Unit]
Description=Start ELK (Elastic search, Logstash and Kibana) at startup
After=network.target
Requires=docker.service

[Service]
Type=simple
KillMode=none
ExecStart=/usr/bin/docker start -a elk
ExecStop=/usr/bin/docker stop -t 5 elk

[Install]
WantedBy=default.target
sudo systemctl daemon-reload
sudo systemctl enable elk

将实体与搜索索引相关联

在配置文件中添加以下内容

fos_elastica:
    clients:
        default:
            host: localhost
            port: 9200
    indexes:
        global:
            types:

                # Below is an example about how to map an entity to a search index

                user:
                    properties:
                        username: ~
                        email: ~
                    persistence:
                        driver: orm
                        model: "%sil.model.user.class%"
                        listener: ~ # by default, listens to "insert", "update" and "delete"

填充索引

运行 FOSElasticaBundle 命令 bin/console fos:elastica:populate 以初始化弹性搜索索引。