我有一个API实现可与Elasticsearch 6.x进行交互,所有索引任务均正常运行。现在,我正在尝试使用批量API为文档建立索引,但在过去5天的xD中没有成功。
我遵循了docs,我的$ params像这样:
[
"body" => [
0 => [
"index" => [
"_index" => "test_schema",
"_type" => "_doc",
"_id" => "1"
]
],
1 => [
"field" => "value"
],
2 => [
"index" => [
"_index" => "test_schema",
"_type" => "_doc",
"_id" => "2"
]
],
3 => [
"field" => "value"
]
]
]
但始终返回此异常:
PHPUnit 7.3.5 by Sebastian Bergmann and contributors.
[
"message" => ""0" is not a valid parameter. Allowed parameters are "_source", "_source_exclude", "_source_include", "client", "consistency", "custom", "fields", "filter_path", "human", "pipeline", "pipeline", "refresh", "replication", "type"",
"exception" => "Elasticsearch\Common\Exceptions\UnexpectedValueException",
"file" => "/home/vagrant/code/my-project/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Endpoints/AbstractEndpoint.php",
"line" => 237,
"trace" => [
0 => [
"file" => "/home/vagrant/code/my-project/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Endpoints/AbstractEndpoint.php",
"line" => 74,
"function" => "checkUserParams",
"class" => "Elasticsearch\Endpoints\AbstractEndpoint",
"type" => "->",
],
1 => [
"file" => "/home/vagrant/code/my-project/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Client.php",
"line" => 747,
"function" => "setParams",
"class" => "Elasticsearch\Endpoints\AbstractEndpoint",
"type" => "->",
],
2 => [
"function" => "bulk",
"class" => "Elasticsearch\Client",
"type" => "->",
],
3 => [
"file" => "/home/vagrant/code/my-project/app/Contracts/SearchProvider/Client/ClientAbstract.php",
"line" => 45,
"function" => "call_user_func",
],
4 => [
"file" => "/home/vagrant/code/my-project/app/Services/Elasticsearch/Document/DocumentHandler.php",
"line" => 131,
"function" => "__call",
"class" => "App\Contracts\SearchProvider\Client\ClientAbstract",
"type" => "->",
],
5 => [
"file" => "/home/vagrant/code/my-project/app/Http/Controllers/DocumentController.php",
"line" => 90,
"function" => "create",
"class" => "App\Services\Elasticsearch\Document\DocumentHandler",
"type" => "->",
],
6 => [
"function" => "App\Http\Controllers\{closure}",
"class" => "App\Http\Controllers\DocumentController",
"type" => "->",
],
7 => [
"file" => "/home/vagrant/code/my-project/app/Http/Controllers/DocumentController.php",
"line" => 91,
"function" => "array_map",
],
8 => [
"function" => "store",
"class" => "App\Http\Controllers\DocumentController",
"type" => "->",
],
9 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Controller.php",
"line" => 54,
"function" => "call_user_func_array",
],
10 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php",
"line" => 45,
"function" => "callAction",
"class" => "Illuminate\Routing\Controller",
"type" => "->",
],
11 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
"line" => 212,
"function" => "dispatch",
"class" => "Illuminate\Routing\ControllerDispatcher",
"type" => "->",
],
12 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
"line" => 169,
"function" => "runController",
"class" => "Illuminate\Routing\Route",
"type" => "->",
],
13 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line" => 679,
"function" => "run",
"class" => "Illuminate\Routing\Route",
"type" => "->",
],
14 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line" => 30,
"function" => "Illuminate\Routing\{closure}",
"class" => "Illuminate\Routing\Router",
"type" => "->",
],
15 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php",
"line" => 41,
"function" => "Illuminate\Routing\{closure}",
"class" => "Illuminate\Routing\Pipeline",
"type" => "->",
],
16 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line" => 151,
"function" => "handle",
"class" => "Illuminate\Routing\Middleware\SubstituteBindings",
"type" => "->",
],
17 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line" => 53,
"function" => "Illuminate\Pipeline\{closure}",
"class" => "Illuminate\Pipeline\Pipeline",
"type" => "->",
],
18 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php",
"line" => 58,
"function" => "Illuminate\Routing\{closure}",
"class" => "Illuminate\Routing\Pipeline",
"type" => "->",
],
19 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line" => 151,
"function" => "handle",
"class" => "Illuminate\Routing\Middleware\ThrottleRequests",
"type" => "->",
],
20 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line" => 53,
"function" => "Illuminate\Pipeline\{closure}",
"class" => "Illuminate\Pipeline\Pipeline",
"type" => "->",
],
21 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line" => 104,
"function" => "Illuminate\Routing\{closure}",
"class" => "Illuminate\Routing\Pipeline",
"type" => "->",
],
22 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line" => 681,
"function" => "then",
"class" => "Illuminate\Pipeline\Pipeline",
"type" => "->",
],
23 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line" => 656,
"function" => "runRouteWithinStack",
"class" => "Illuminate\Routing\Router",
"type" => "->",
],
24 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line" => 622,
"function" => "runRoute",
"class" => "Illuminate\Routing\Router",
"type" => "->",
],
25 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line" => 611,
"function" => "dispatchToRoute",
"class" => "Illuminate\Routing\Router",
"type" => "->",
],
26 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line" => 176,
"function" => "dispatch",
"class" => "Illuminate\Routing\Router",
"type" => "->",
],
27 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line" => 30,
"function" => "Illuminate\Foundation\Http\{closure}",
"class" => "Illuminate\Foundation\Http\Kernel",
"type" => "->",
],
28 => [
"file" => "/home/vagrant/code/my-project/app/Http/Middleware/SearchProviderConnect.php",
"line" => 27,
"function" => "Illuminate\Routing\{closure}",
"class" => "Illuminate\Routing\Pipeline",
"type" => "->",
],
29 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line" => 151,
"function" => "handle",
"class" => "App\Http\Middleware\SearchProviderConnect",
"type" => "->",
],
30 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line" => 53,
"function" => "Illuminate\Pipeline\{closure}",
"class" => "Illuminate\Pipeline\Pipeline",
"type" => "->",
],
31 => [
"file" => "/home/vagrant/code/my-project/vendor/spatie/laravel-cors/src/Cors.php",
"line" => 28,
"function" => "Illuminate\Routing\{closure}",
"class" => "Illuminate\Routing\Pipeline",
"type" => "->",
],
32 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line" => 151,
"function" => "handle",
"class" => "Spatie\Cors\Cors",
"type" => "->",
],
33 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line" => 53,
"function" => "Illuminate\Pipeline\{closure}",
"class" => "Illuminate\Pipeline\Pipeline",
"type" => "->",
],
34 => [
"file" => "/home/vagrant/code/my-project/vendor/fideloper/proxy/src/TrustProxies.php",
"line" => 57,
"function" => "Illuminate\Routing\{closure}",
"class" => "Illuminate\Routing\Pipeline",
"type" => "->",
],
35 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line" => 151,
"function" => "handle",
"class" => "Fideloper\Proxy\TrustProxies",
"type" => "->",
],
36 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line" => 53,
"function" => "Illuminate\Pipeline\{closure}",
"class" => "Illuminate\Pipeline\Pipeline",
"type" => "->",
],
37 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
"line" => 31,
"function" => "Illuminate\Routing\{closure}",
"class" => "Illuminate\Routing\Pipeline",
"type" => "->",
],
38 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line" => 151,
"function" => "handle",
"class" => "Illuminate\Foundation\Http\Middleware\TransformsRequest",
"type" => "->",
],
39 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line" => 53,
"function" => "Illuminate\Pipeline\{closure}",
"class" => "Illuminate\Pipeline\Pipeline",
"type" => "->",
],
40 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
"line" => 31,
"function" => "Illuminate\Routing\{closure}",
"class" => "Illuminate\Routing\Pipeline",
"type" => "->",
],
41 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line" => 151,
"function" => "handle",
"class" => "Illuminate\Foundation\Http\Middleware\TransformsRequest",
"type" => "->",
],
42 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line" => 53,
"function" => "Illuminate\Pipeline\{closure}",
"class" => "Illuminate\Pipeline\Pipeline",
"type" => "->",
],
43 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php",
"line" => 27,
"function" => "Illuminate\Routing\{closure}",
"class" => "Illuminate\Routing\Pipeline",
"type" => "->",
],
44 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line" => 151,
"function" => "handle",
"class" => "Illuminate\Foundation\Http\Middleware\ValidatePostSize",
"type" => "->",
],
45 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line" => 53,
"function" => "Illuminate\Pipeline\{closure}",
"class" => "Illuminate\Pipeline\Pipeline",
"type" => "->",
],
46 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php",
"line" => 62,
"function" => "Illuminate\Routing\{closure}",
"class" => "Illuminate\Routing\Pipeline",
"type" => "->",
],
47 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line" => 151,
"function" => "handle",
"class" => "Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode",
"type" => "->",
],
48 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
"line" => 53,
"function" => "Illuminate\Pipeline\{closure}",
"class" => "Illuminate\Pipeline\Pipeline",
"type" => "->",
],
49 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line" => 104,
"function" => "Illuminate\Routing\{closure}",
"class" => "Illuminate\Routing\Pipeline",
"type" => "->",
],
50 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line" => 151,
"function" => "then",
"class" => "Illuminate\Pipeline\Pipeline",
"type" => "->",
],
51 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line" => 116,
"function" => "sendRequestThroughRouter",
"class" => "Illuminate\Foundation\Http\Kernel",
"type" => "->",
],
52 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php",
"line" => 345,
"function" => "handle",
"class" => "Illuminate\Foundation\Http\Kernel",
"type" => "->",
],
53 => [
"file" => "/home/vagrant/code/my-project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php",
"line" => 317,
"function" => "call",
"class" => "Illuminate\Foundation\Testing\TestCase",
"type" => "->",
],
54 => [
"file" => "/home/vagrant/code/my-project/tests/Feature/Controller/DocumentController.php",
"line" => 121,
"function" => "json",
"class" => "Illuminate\Foundation\Testing\TestCase",
"type" => "->",
],
55 => [
"file" => "/home/vagrant/code/my-project/vendor/phpunit/phpunit/src/Framework/TestCase.php",
"line" => 1150,
"function" => "storeDocument",
"class" => "Tests\Feature\SearchProvider\Elasticsearch\DocumentControllerTest",
"type" => "->",
],
56 => [
"file" => "/home/vagrant/code/my-project/vendor/phpunit/phpunit/src/Framework/TestCase.php",
"line" => 844,
"function" => "runTest",
"class" => "PHPUnit\Framework\TestCase",
"type" => "->",
],
57 => [
"file" => "/home/vagrant/code/my-project/vendor/phpunit/phpunit/src/Framework/TestResult.php",
"line" => 665,
"function" => "runBare",
"class" => "PHPUnit\Framework\TestCase",
"type" => "->",
],
58 => [
"file" => "/home/vagrant/code/my-project/vendor/phpunit/phpunit/src/Framework/TestCase.php",
"line" => 798,
"function" => "run",
"class" => "PHPUnit\Framework\TestResult",
"type" => "->",
],
59 => [
"file" => "/home/vagrant/code/my-project/vendor/phpunit/phpunit/src/Framework/TestSuite.php",
"line" => 750,
"function" => "run",
"class" => "PHPUnit\Framework\TestCase",
"type" => "->",
],
60 => [
"file" => "/home/vagrant/code/my-project/vendor/phpunit/phpunit/src/TextUI/TestRunner.php",
"line" => 586,
"function" => "run",
"class" => "PHPUnit\Framework\TestSuite",
"type" => "->",
],
61 => [
"file" => "/home/vagrant/code/my-project/vendor/phpunit/phpunit/src/TextUI/Command.php",
"line" => 203,
"function" => "doRun",
"class" => "PHPUnit\TextUI\TestRunner",
"type" => "->",
],
62 => [
"file" => "/home/vagrant/code/my-project/vendor/phpunit/phpunit/src/TextUI/Command.php",
"line" => 159,
"function" => "run",
"class" => "PHPUnit\TextUI\Command",
"type" => "->",
],
63 => [
"file" => "/home/vagrant/code/my-project/vendor/phpunit/phpunit/phpunit",
"line" => 53,
"function" => "main",
"class" => "PHPUnit\TextUI\Command",
"type" => "::",
]
]
]
我不知道为什么,我查看了elasticsearch php sdk代码,但没有任何线索。有谁知道这里发生的事情吗?
预先感谢您的关注。
更新:
我有一个ClientAbstract类,该类封装了第三方“客户端”实现(在本例中为Elasticsearch \ ClientBuilde),因此,要调用任何与Elasticsearch相关的问题,我将必须抽象每个方法。
为了避免这项繁重的工作,我只实现了一个魔术方法'__call':
public function __call(string $name, array $arguments)
{
return call_user_func([$this->client, $name], $arguments);
}
答案 0 :(得分:0)
该错误与我的“ __call”实现有关”,我使用的是“ call_user_func”,应该使用“ call_user_func_array” ...此修复程序如下:
public function __call(string $name, array $arguments)
{
return call_user_func_array([$this->client, $name], $arguments);
}
或使用“ ...”运算符:
public function __call(string $name, array $arguments)
{
return call_user_func([$this->client, $name], ...$arguments);
}
那是因为“ $ arguments”始终是一个数组,所以传递给Elasticsearch客户端的实际数据是:
[
0 => [
"body" => [
0 => [
"index" => [
"_index" => "test_schema",
"_type" => "_doc",
"_id" => "1"
]
],
1 => [
"field" => "value"
],
2 => [
"index" => [
"_index" => "test_schema",
"_type" => "_doc",
"_id" => "2"
]
],
3 => [
"field" => "value"
]
]
]
]
这说明“ 0”不是有效参数。允许的参数为“ _source”,“ _ source_exclude”,“ _ source_include”,“ client”,“ consistency”,“ custom”,“ fields”,
“ filter_path”,“ human”,“ pipeline”,“ pipeline”,“ refresh”,“ replication”,“ type”” 事物。