5

I am trying to add documents to ElasticSearch. I have no problems using curl from the command line, but I'm having trouble when using curl in PHP. I'm following this example from the docs: http://www.elasticsearch.org/guide/reference/api/index_.html

The following code is giving me this error: {"error":"IndexMissingException[[twitter] missing]","status":404}

$search_host = '127.0.0.1';
$search_port = '9200';
$index = 'twitter';
$doc_type = 'tweet';
$doc_id = 1;

    $json_doc = array(
                "user" => "kimchy",
                "post_date" => "2012-11-15T14:12:12",
                "message" => "trying out Elastic Search"
            );
    $json_doc = json_encode($json_doc);

    $baseUri = 'http://'.$search_host.':'.$search_port.'/'.$index.'/'.$doc_type.'/'.$doc_id;

    $ci = curl_init();
    curl_setopt($ci, CURLOPT_URL, $baseUri);
    curl_setopt($ci, CURLOPT_PORT, $search_port);
    curl_setopt($ci, CURLOPT_TIMEOUT, 200);
    curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ci, CURLOPT_FORBID_REUSE, 0);
    curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'XPUT');
    curl_setopt($ci, CURLOPT_POSTFIELDS, $json_doc);
    $response = curl_exec($ci);
2
  • Have you tried to use XPOST instead of XPUT? Commented Nov 27, 2012 at 13:25
  • Yes, the error is the same with XPOST, but thanks for the suggestion. Commented Nov 27, 2012 at 18:38

1 Answer 1

9

You have to set the the curl option CURLOPT_CUSTOMREQUEST to PUT, not XPUT.

curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'PUT');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.