Elasticsearch PHP client help needed


(mrblue) #1

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 :wink:

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 ?


(Douglas Muth) #2

On Fri, Dec 30, 2011 at 12:56 AM, mrblue
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


(mrblue) #3

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/ -
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 wrote:

On Fri, Dec 30, 2011 at 12:56 AM, mrblue

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


(ruflin-2) #4

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

Here is also some documentation: http://ruflin.github.com/Elastica/

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


(Douglas Muth) #5

On Fri, Dec 30, 2011 at 5:31 AM, mrblue 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/ -
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. :slight_smile:

-- Doug

--
http://twitter.com/dmuth


(system) #6