# Help with PHP wrapper for \_suggest query

**URL:** <https://discuss.elastic.co/t/help-with-php-wrapper-for--suggest-query/14247>\
**Category:** Elasticsearch\
**Created:** [November 4, 2013, 6:10pm UTC](https://discuss.elastic.co/t/help-with-php-wrapper-for--suggest-query/14247 "2013-11-04T18:10:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevins/32/946_2.png) [@kevins](https://discuss.elastic.co/u/kevins)\
**Post date:** [November 4, 2013, 6:10pm UTC](https://discuss.elastic.co/t/help-with-php-wrapper-for--suggest-query/14247/1 "2013-11-04T18:10:34Z")

</div>

I am using this simple constructor class for PHP calls to ES.

> <https://github.com/hasantayyar/elasticsearch-php/blob/master/ElasticSearch.php>

I am trying to add a stub for the following suggest query:

curl -XPOST 'localhost:9200/\_suggest' -d '{  
"my-suggestion" : {  
"text" : "the amsterdma meetpu",  
"term" : {  
"field" : "body"  
}  
}  
}'

Which is seen here:  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters.html)

What I get back is 404's from ES saying exists:"false"

Here is the code I am trying:

//curl -X GET [http://localhost:9200/{INDEX}/{TYPE}/\_suggest?q=](http://localhost:9200/%7BINDEX%7D/%7BTYPE%7D/_suggest?q=) ...  
function suggest($type, $q, $size=5) {

```
    $suggestion = array('my-suggestion' => array('text' => $q,'term' =>array

```

('size' =\> $size, 'field' =\> 'title')));  
return $this-\>call($type . '/\_suggest?' . http\_build\_query(  
$suggestion));

```
}

```

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [November 5, 2013, 3:00pm UTC](https://discuss.elastic.co/t/help-with-php-wrapper-for--suggest-query/14247/2 "2013-11-05T15:00:19Z")

</div>

I don't believe the Suggest endpoint supports `q` parameters, you'll need  
to send a request body instead. The best way to debug it is to print out  
the URI and body before the curl request is network request is made, then  
see if that runs as a curl command. Adjust as necessary to make the curl  
work, then translate back to PHP.

Related, there is an official Elasticsearch-PHP client in case you didn't  
know about it. The client supports the full  
API: [GitHub - elastic/elasticsearch-php: Official PHP client for Elasticsearch.](https://github.com/elasticsearch/elasticsearch-php)

-Zach

On Monday, November 4, 2013 1:10:34 PM UTC-5, Kevin S wrote:

> I am using this simple constructor class for PHP calls to ES.
> 
> [https://github.com/hasantayyar/elasticsearch-php/blob/master/ElasticSearch.php](https://github.com/hasantayyar/elasticsearch-php/blob/master/ElasticSearch.php)
> 
> I am trying to add a stub for the following suggest query:
> 
> curl -XPOST 'localhost:9200/\_suggest' -d '{  
> "my-suggestion" : {  
> "text" : "the amsterdma meetpu",  
> "term" : {  
> "field" : "body"  
> }  
> }  
> }'
> 
> Which is seen here:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters.html)
> 
> What I get back is 404's from ES saying exists:"false"
> 
> Here is the code I am trying:
> 
> //curl -X GET [http://localhost:9200/{INDEX}/{TYPE}/\_suggest?q=](http://localhost:9200/%7BINDEX%7D/%7BTYPE%7D/_suggest?q=) ...  
> function suggest($type, $q, $size=5) {
> 
> ```
> $suggestion = array('my-suggestion' => array('text' => $q,'term' 
> 
> ```
> 
> =\> array('size' =\> $size, 'field' =\> 'title')));  
> return $this-\>call($type . '/\_suggest?' . http\_build\_query(  
> $suggestion));
> 
> ```
> }
> 
> ```

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:08am UTC](https://discuss.elastic.co/t/help-with-php-wrapper-for--suggest-query/14247/3 "2017-07-06T02:08:50Z")

</div>


