1

我在 Platform.sh 上的 Symfony 4.4 上使用 FOS Elasticsearch 包,任何填充结果的尝试都会出错。

相关配置部分:

作曲家.json

"require": {
    "php": ">=7.3.0",
    ...
    "friendsofsymfony/elastica-bundle": "^5.1",

平台/服务.yml

searchelastic77:
    type: elasticsearch:7.7
    disk: 1024

.platform.app.yml

relationships:
    ...
    elasticsearch: "searchelastic77:elasticsearch"

配置/包/fos_elastica.yml

fos_elastica:
    clients:
        default: { url: '%env(ELASTICSEARCH_URL)%' }
    indexes:
        app_post:
            types:
                post:
                    properties:
                        title: ~
                        excerpt: ~
                        content: ~
                        author: ~
                    persistence:
                        driver: orm
                        model: App\Entity\Post
                        provider: ~
                        finder: ~

.env

###> friendsofsymfony/elastica-bundle ###
ELASTICSEARCH_URL=http://localhost:9200/
###< friendsofsymfony/elastica-bundle ###

在此分支的 platform.sh 设置中,我配置了以下变量:

env:ELASTICSEARCH_URL = http://elasticsearch.internal:9200

platform:relationships在此分支上运行会产生:

elasticsearch:
    -
        service: searchelastic77
        ip: ***
        cluster: ***
        host: elasticsearch.internal
        rel: elasticsearch
        scheme: http
        port: 9200
        url: 'http://elasticsearch.internal:9200'

错误似乎与不正确的 HTTP 方法有关。尝试通过运行命令来填充实时服务器上的索引会bin/console fos:elastica:populate产生以下异常:

Resetting app_post

In Http.php line 182:
                                                                                    
  Incorrect HTTP method for uri [/] and method [PUT], allowed: [GET, DELETE, HEAD]  
                                                                                    

fos:elastica:populate [--index [INDEX]] [--type [TYPE]] [--no-reset] [--no-delete] [--sleep SLEEP] [--ignore-errors] [--no-overwrite-format] [--first-page FIRST-PAGE] [--last-page LAST-PAGE] [--max-per-page MAX-PER-PAGE] [--pager-persister PAGER-PERSISTER] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>

尝试更新生产服务器上的 post 实体也会产生此错误:

request.CRITICAL: Uncaught PHP Exception Elastica\Exception\ResponseException: "Incorrect HTTP method for uri [/] and method [POST], allowed: [GET, DELETE, HEAD]" at /app/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php line 182 {"exception":"[object] (Elastica\\Exception\\ResponseException(code: 0): Incorrect HTTP method for uri [/] and method [POST], allowed: [GET, DELETE, HEAD] at /app/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php:182)"} []

我尝试了 Elastic 搜索版本(5.2、6.5 和现在的 7.7)的各种组合,并且都抛出了相同的错误。

4

0 回答 0