# Elasticsearch PHP client help needed

**URL:** <https://discuss.elastic.co/t/elasticsearch-php-client-help-needed/6258>\
**Category:** Elasticsearch\
**Created:** [December 30, 2011, 5:56am UTC](https://discuss.elastic.co/t/elasticsearch-php-client-help-needed/6258 "2011-12-30T05:56:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrblue](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mrblue/32/23268_2.png) [@mrblue](https://discuss.elastic.co/u/mrblue)\
**Post date:** [December 30, 2011, 5:56am UTC](https://discuss.elastic.co/t/elasticsearch-php-client-help-needed/6258/1 "2011-12-30T05:56:27Z")

</div>

So i have my little script and search running, now i need to populate  
my database.. I was not able to populate my DB with libcurl/php, so i  
decided to try the php client.

Now talk about poor documentation 😉

This codes enters values in my DB, but i don´t know why and how to  
manipulate it:

require\_once "ElasticSearchClient.php";  
$transport = new ElasticSearchTransportHTTP("localhost", 9200);  
$search = new ElasticSearchClient($transport, "twitter", "mytype");  
$search-\>index(array('title' =\> 'My cool document'), $id);  
$search-\>get($id);  
$search-\>search('title:cool');

However, the doc says that i can use the query DSL wich would be nice  
as i learned quite a little bit the last days..

Doc says:  
$search-\>search(array(  
'query' =\> array(  
'term' =\> array('title' =\> 'cool')  
)  
);

But this is obv wrong and i get lots of errors like: unexpected ';'  
etc..  
So my questions are:  
(1) can i just execute any query DSL in the php client ? That would be  
amazing !  
(2) Can someone post a working snippet ?

---

<div class="post-metadata">

**Author:** ![Douglas\_Muth](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/douglas_muth/32/29006_2.png) [@Douglas\_Muth](https://discuss.elastic.co/u/Douglas_Muth)\
**Post date:** [December 30, 2011, 6:02am UTC](https://discuss.elastic.co/t/elasticsearch-php-client-help-needed/6258/2 "2011-12-30T06:02:10Z")

</div>

On Fri, Dec 30, 2011 at 12:56 AM, mrblue  
[john.agricola.27@googlemail.com](mailto:john.agricola.27@googlemail.com) wrote:

> So i have my little script and search running, now i need to populate  
> my database.. I was not able to populate my DB with libcurl/php, so i  
> decided to try the php client.

What issues did you run into PHP's libcurl? I successfully used it to  
populate and search Elastic Search at $WORK, and it worked great for  
that purpose.

-- Doug

---

<div class="post-metadata">

**Author:** ![mrblue](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mrblue/32/23268_2.png) [@mrblue](https://discuss.elastic.co/u/mrblue)\
**Post date:** [December 30, 2011, 11:31am UTC](https://discuss.elastic.co/t/elasticsearch-php-client-help-needed/6258/3 "2011-12-30T11:31:49Z")

</div>

Hi,

i just can´t find the right syntax ! Do you have some working code ? I  
tried something like this:

$ch = curl\_init();  
curl\_setopt($ch, CURLOPT\_URL, "[http://localhost:9200/twitter/tweet/](http://localhost:9200/twitter/tweet/) -  
d");  
curl\_setopt($ch, CURLOPT\_RETURNTRANSFER, TRUE);  
curl\_setopt($ch, CURLOPT\_CUSTOMREQUEST, 'PUT');  
curl\_setopt($ch, CURLOPT\_POST, true);

$data = '{  
"user": "kimchy",  
"message": "Trying out elasticsearch, so far so good?"  
}';

curl\_setopt($ch, CURLOPT\_POSTFIELDS, $data);  
$jason\_output = curl\_exec($ch);  
$info = curl\_getinfo($ch);  
curl\_close($ch);

But i either get some errors like "caught exeption while handling  
client http traffic" blablabla or no message at all..

On Dec 30, 7:02 am, Douglas Muth [doug.m...@gmail.com](mailto:doug.m...@gmail.com) wrote:

> On Fri, Dec 30, 2011 at 12:56 AM, mrblue
> 
> [john.agricola...@googlemail.com](mailto:john.agricola...@googlemail.com) wrote:
> 
> > So i have my little script and search running, now i need to populate  
> > my database.. I was not able to populate my DB with libcurl/php, so i  
> > decided to try the php client.
> 
> What issues did you run into PHP's libcurl? I successfully used it to  
> populate and search Elastic Search at $WORK, and it worked great for  
> that purpose.
> 
> -- Doug

---

<div class="post-metadata">

**Author:** ![ruflin\_2](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@ruflin\_2](https://discuss.elastic.co/u/ruflin_2)\
**Post date:** [December 31, 2011, 10:35am UTC](https://discuss.elastic.co/t/elasticsearch-php-client-help-needed/6258/4 "2011-12-31T10:35:02Z")

</div>

Perhaps it helps if you take a look at my Elastica PHP  
client: [https://github.com/ruflin/Elastica](https://github.com/ruflin/Elastica)

Here is also some documentation: [http://ruflin.github.com/Elastica/](http://ruflin.github.com/Elastica/)

If you need to now how to use a specific query, check out the tests on  
github.

---

<div class="post-metadata">

**Author:** ![Douglas\_Muth](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/douglas_muth/32/29006_2.png) [@Douglas\_Muth](https://discuss.elastic.co/u/Douglas_Muth)\
**Post date:** [December 31, 2011, 6:09pm UTC](https://discuss.elastic.co/t/elasticsearch-php-client-help-needed/6258/5 "2011-12-31T18:09:45Z")

</div>

On Fri, Dec 30, 2011 at 5:31 AM, mrblue [john.agricola.27@googlemail.com](mailto:john.agricola.27@googlemail.com) wrote:

> Hi,
> 
> i just can´t find the right syntax ! Do you have some working code ? I  
> tried something like this:
> 
> $ch = curl\_init();  
> curl\_setopt($ch, CURLOPT\_URL, "[http://localhost:9200/twitter/tweet/](http://localhost:9200/twitter/tweet/) -  
> d");  
> [snip]

There's your culprit: you have the "-d" in your URL there. That  
option is for when you run cURL from the command line. It's not  
necessary in PHP. 🙂

-- Doug

--  
[http://twitter.com/dmuth](http://twitter.com/dmuth)

---

<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, 3:44am UTC](https://discuss.elastic.co/t/elasticsearch-php-client-help-needed/6258/6 "2017-07-06T03:44:04Z")

</div>


