![](/img/trans.png)
[英]Elasticsearch Bulk Indexing Error Message : %s% is not a valid parameter. Allowed parameters are: %s%
[英]PHP Elasticsearch Bulk Index Issue: “”0“ is not a valid parameter. Allowed parameters are …”
我有一個與Elasticsearch 6.x交互的API實現,所有索引任務都可以正常工作。 現在,我嘗試使用批量api為文檔建立索引,但在過去5天的xD中沒有成功。
我遵循了文檔 ,我的$ 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);
}
錯誤與我的“ __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” “,”管道“,”管道“,”刷新“,”復制“,”類型“”的東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.