PHP Elasticsearch Bulk Index Issue: "" 0 "не является допустимым параметром. Допустимыми параметрами являются ..." - PullRequest
0 голосов
/ 04 октября 2018

У меня есть реализация 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" => "::",
        ]
    ]
]

Я не знаю почему, я посмотрел код phpasticsearch php, но никаких подсказок.Кто-нибудь знает, что здесь происходит?

Заранее благодарю за внимание.

ОБНОВЛЕНИЕ:

У меня есть класс ClientAbstract, который инкапсулирует сторонний "клиент"«Реализация (в данном случае Elasticsearch \ ClientBuilde), поэтому для вызова любых проблем, связанных с Elasticsearch, мне нужно было бы абстрагировать каждый метод.

Чтобы избежать этой тяжелой работы, я просто реализовал магический метод __call.:

public function __call(string $name, array $arguments)
{
    return call_user_func([$this->client, $name], $arguments);
}

1 Ответ

0 голосов
/ 04 октября 2018

Ошибка была связана с моей реализацией "__call", я использую "call_user_func", где я должен использовать "call_user_func_array" ... исправление ниже:

public function __call(string $name, array $arguments)
{
    return call_user_func_array([$this->client, $name], $arguments);
}

Или используйте '... 'operator:

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", "консистенция", "custom", "fields", "filter_path", "human", "pipe", "pipe", "pipe", "refresh", "репликация", "тип" " вещь.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...