Elasticsearch completion suggester query in PHP

后端 未结 2 614
盖世英雄少女心
盖世英雄少女心 2021-01-24 11:05

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

Querying via CURL, e.g.



        
相关标签:
2条回答
  • 2021-01-24 11:34

    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);
    
    0 讨论(0)
  • 2021-01-24 11:59

    Using the PHP elasticsearch 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);
    
    0 讨论(0)
提交回复
热议问题