enterprise-search-php icon indicating copy to clipboard operation
enterprise-search-php copied to clipboard

Document class not found in AppSearch/Request namespace

Open sonklein opened this issue 1 year ago • 1 comments

Hi,

I'm fairly new to AppSearch and found this library to help me setting up my calls to our APIs I'm in charge to index files in our engine so i used the AppSearch\Request\IndexDocuments class that looks like this :


/**
 * Elastic Enterprise Search
 *
 * @link      https://github.com/elastic/enterprise-search-php
 * @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co)
 * @license   https://opensource.org/licenses/MIT MIT License
 *
 * Licensed to Elasticsearch B.V under one or more agreements.
 * Elasticsearch B.V licenses this file to you under the MIT License.
 * See the LICENSE file in the project root for more information.
 */

declare(strict_types=1);

namespace Elastic\EnterpriseSearch\AppSearch\Request;

use Elastic\EnterpriseSearch\Request\Request;

/**
 * Create a new document
 *
 * @see https://www.elastic.co/guide/en/app-search/current/documents.html#documents-create
 * @generated This file is generated, please do not edit
 */
class IndexDocuments extends Request
{
	/**
	 * @param string $engineName Name of the engine
	 * @param Document[] $documents
	 */
	public function __construct(string $engineName, array $documents = null)
	{
		$this->method = 'POST';
		$engine_name = urlencode($engineName);
		$this->path = "/api/as/v1/engines/$engine_name/documents";
		$this->headers['Content-Type'] = 'application/json';
		$this->body = $documents;
	}
}

In the param section, it says it uses a Document[] array to send them. I used the "AppSearch\Schema\Document" class to index my documents but since there isn't any "use " of this class in the IndexDocuments class, it looks for an "AppSearch\Request\Document" class that does not exist. It works as expected (i can actually send the documents) but quality code fails (also PHPStorm triggers a warning) so maybe adding the proper "use" should be able to fix this ?

Or maybe i'm totally wrong somewhere and you can help me :)

Also : I use the 8.4 version

sonklein avatar Oct 12 '22 12:10 sonklein

@sonklein thanks for reporting the issue! It seems an issue of the code generator, we forgot to set the use when we specify a type property in phpdoc.The Document class lives in Elastic\EnterpriseSearch\AppSearch\Schema.

ezimuel avatar Oct 19 '22 07:10 ezimuel