PHP中的Elasticsearch完成建议者查询 [英] Elasticsearch completion suggester query in PHP

查看:181
本文介绍了PHP中的Elasticsearch完成建议者查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到如何使用PHP(elasticsearch-php)中的完成建议器查询Elasticsearch的有效示例。

I was not able to find a working example on how to query Elasticsearch using the completion suggester in PHP (elasticsearch-php).

通过CURL查询,例如

Querying via CURL, e.g.

curl -X POST 'localhost:9200/tstidx/_suggest?pretty' -d '{
"try" : {
    "text" : "a",
    "completion" : {
        "field" : "suggest"
    }
}
}'

可以工作,所以唯一的问题是PHP中的查询部分。

works, so the only problem is the query part in PHP.

如何使用API​​通过完成建议器查询Elasticsearch?

How do I use the API to query Elasticsearch using the completion suggester?

推荐答案

PHP ES客户端具有一种名为 的方法建议 可以用于此目的:

The PHP ES client has a method called suggest that you can use for that purpose:

$params = [
    'index' => 'tstidx',
    'body' => [
        'try' => [
            'text' => 'a',
            'completion' => [ 'field' => 'suggest' ]
        ]
    ]
];

$client = ClientBuilder::create()->build();
$response = $client->suggest($params);

这篇关于PHP中的Elasticsearch完成建议者查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆