【发布时间】:2022-01-16 22:20:53
【问题描述】:
当尝试通过 fos_elastica-bundle (v6.0.0) 将 elasticsearch (v7.9.3) 实现到我的 Symfony (v5.3.10) - 带有 api_platform (v2.6.6) 的应用程序时,我不断收到此错误:
"{"error":"no handler found for uri [//posts/_doc/_search] and method [POST]"}",
我的 api_platform.yaml 内容如下:
api_platform:
[...]
elasticsearch:
hosts: [ '%env(ELASTICSEARCH_URL)%' ]
mapping:
App\Document\Post:
index: posts
还有我的 fos_elastica.yaml:
fos_elastica:
clients:
default: { url: '%env(ELASTICSEARCH_URL)%' }
indexes:
posts:
properties:
id:
"type": "keyword"
source: ~
title: ~
description: ~
body: ~
children: ~
tags: ~
originalContent: ~
persistence:
driver: mongodb
model: App\Document\Post
通过调试 fos-elastica Bundle,我发现 Elastica-Connector 使用此请求正文正确触发了 [POST]-Request 到“/posts/_doc/_search”:
{"sort":[{"id":{"order":"asc"}}],"query":{"match_all":{}},"size":30,"from":0}
如果我使用 Kibana 开发工具控制台并触发相同的请求
POST /posts/_doc/_search
{"sort":[{"id":{"order":"asc"}}],"query":{"match_all":{}},"size":30,"from":60}
我确实按预期从弹性搜索中获得了结果:
#! Deprecation: [types removal] Specifying types in search requests is deprecated.
{
"took" : 12,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3082,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "posts",
"_type" : "_doc",
[...]
除了弃用通知,一切似乎都很好。
有谁知道为什么 fos_elastica-bundle 的 api_platform 集成无法按预期工作并不断返回“未找到处理程序”错误消息?
-
您的 PHP 路径中是否有额外的前导
/
?两个/
s 从这里开始://posts/_doc/_search'
让我紧张 -
是的,在 api_platform 计算的路径中有一个前导 /。我不知道它来自哪里,但我怀疑它会导致所描述的错误。如果我使用 Kibana 开发工具控制台触发带有两个前导斜杠的请求(即 POST //posts/_doc/_search),我仍然会得到相同(正确)的响应。
-
仍然没有找到解决方案。有人可以帮忙吗?