elastic/enterprise-search-php

How to limit result fields ?

nd- opened this issue · 1 comments

nd- commented

Hello,
I can't figure how to use the result_fields of the SearchRequestParams.

Here's what i do :

$client = new Client([
	'host' => ELASTIC_API_ENDPOINT,
	'apiKey' => ELASTIC_API_TOKEN,
	'logger' => $logger,
]);
$appSearch = $client->appSearch();
$search = new SearchRequestParams($term);
$search->page = new PaginationResponseObject();
$search->page->size = ($max_results ?: 25);
$search->result_fields = new SimpleObject();
$search->result_fields->body_content = 'raw';
$request = new Request\Search($engine, $search);
$searchResults = $appSearch->search($request)->asArray();

Request body :

{"query":"testing","page":{"size":25},"result_fields":{"body_content":"raw"}}

Error 400, response body :

{"errors":["Result fields contains invalid value for field: body_content; must be an object"]}

Without result_fields, everything works fine.

Is it me or is there a problem with result_fields ?

Thanx,

nd- commented

I've read the doc again (https://www.elastic.co/guide/en/app-search/8.5/result-fields-highlights.html) and found how use it:

$searchRequestParams->result_fields = new SimpleObject();
// raw field, no limit
$searchRequestParams->result_fields->page_title = ['raw' => new SimpleObject()];
// raw field, size limit
$searchRequestParams->result_fields->body_content = ['raw' => ['size'=> 250]];