【问题标题】:Elasticsearch completion suggester query in PHPPHP中的Elasticsearch完成建议器查询
【发布时间】:2016-10-30 01:30:42
【问题描述】:

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

通过 CURL 查询,例如

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

有效,所以唯一的问题是 PHP 中的查询部分。

如何通过 API 使用完成提示器查询 Elasticsearch?

【问题讨论】:

    标签: php elasticsearch


    【解决方案1】:

    PHP ES 客户端有一个名为 suggest 的方法,您可以将其用于此目的:

    $params = [
        'index' => 'tstidx',
        'body' => [
            'try' => [
                'text' => 'a',
                'completion' => [ 'field' => 'suggest' ]
            ]
        ]
    ];
    
    $client = ClientBuilder::create()->build();
    $response = $client->suggest($params);
    

    【讨论】:

    【解决方案2】:

    使用 PHP 弹性搜索 API

        <?Php 
           include 'autoload.php';
           $elastic_search = new ElasticApiService();
           $search_params = array(
               'index' => 'my_index',
               'search_type' =>  'match',
               'search_key' => 'citynamefield',
               'search_value' => 'orlando'
           );
           $search_results = $elastic_search->searchElastic($search_params);
           echo '<pre>';
    print_r($search_results);
    

    【讨论】:

    • 引擎7.6.1版本也可以使用通配符
    • { "query": { "query_string" : { "query" : "Orl*", "default_field" : "poname" } } }
    猜你喜欢
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 2020-07-14
    • 2013-02-27
    • 2023-04-06
    • 2023-03-12
    • 2015-02-19
    • 2023-04-08
    相关资源
    最近更新 更多