如何使用php api分析字符串

Jay*_*yni 1 php analyzer query-string elasticsearch

如何使用PHP API来使用此功能.我没有找到方法.

curl -XGET 'localhost:9200/_analyze?analyzer=standard' -d 'this is a test'
Run Code Online (Sandbox Code Playgroud)

我需要访问它,因为我需要访问通过script_score计算我的分数的查询字符串.当然,不分析查询字符串.所以我必须分开做.

我知道这不是一个好的解决方案,但直到现在我才找到一个替代品.

Joh*_*one 5

它在指数名称空间中:

 /**
* $params['index'] = (string) The name of the index to scope the operation
* ['analyzer'] = (string) The name of the analyzer to use
* ['field'] = (string) Use the analyzer configured for this field (instead of passing the analyzer name)
* ['filters'] = (list) A comma-separated list of filters to use for the analysis
* ['prefer_local'] = (boolean) With `true`, specify that a local shard should be used if available, with `false`, use a random shard (default: true)
* ['text'] = (string) The text on which the analysis should be performed (when request body is not used)
* ['tokenizer'] = (string) The name of the tokenizer to use for the analysis
* ['format'] = (enum) Format of the output
* ['body'] = (enum) Format of the output
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function analyze($params = array())
{
$index = $this->extractArgument($params, 'index');
$body = $this->extractArgument($params, 'body');
/** @var callback $endpointBuilder */
$endpointBuilder = $this->dicEndpoints;
/** @var \Elasticsearch\Endpoints\Indices\Analyze $endpoint */
$endpoint = $endpointBuilder('Indices\Analyze');
$endpoint->setIndex($index)
->setBody($body);
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}
Run Code Online (Sandbox Code Playgroud)

https://github.com/elasticsearch/elasticsearch-php/blob/master/src/Elasticsearch/Namespaces/IndicesNamespace.php