Elastic search und Codeigniter (PHP)

Ich versuche mit ElasticSearch mit Codeigniter framework.

Was ich getan habe ist einfach zu installieren, ElasticSearch und copyed ( 😛 ) ein gutes PHP-Bibliothek auf der web-CI-Bibliotheken:

    class Elasticsearch {

  public $config_file = 'elasticsearch';
  public $index;

  function __construct($index = false){
      $CI =& get_instance();
      $CI->config->load($this->config_file);
      $this->server = $CI->config->item('es_server');

  }

  function call($path, $http = array()){
    if (!$this->index) throw new Exception('$this->index needs a value');
    return json_decode(file_get_contents($this->server . '/' . $this->index . '/' . $path, NULL, stream_context_create(array('http' => $http))));
  }

  //curl -X PUT http://localhost:9200/{INDEX}/
  function create(){
     $this->call(NULL, array('method' => 'PUT'));
  }

  //curl -X DELETE http://localhost:9200/{INDEX}/
  function drop(){
     $this->call(NULL, array('method' => 'DELETE'));
  }

  //curl -X GET http://localhost:9200/{INDEX}/_status
  function status(){
    return $this->call('_status');
  }

  //curl -X GET http://localhost:9200/{INDEX}/{TYPE}/_count -d {matchAll:{}}
  function count($type){
    return $this->call($type . '/_count', array('method' => 'GET', 'content' => '{ matchAll:{} }'));
  }

  //curl -X PUT http://localhost:9200/{INDEX}/{TYPE}/_mapping -d ...
  function map($type, $data){
    return $this->call($type . '/_mapping', array('method' => 'PUT', 'content' => $data));
  }

  //curl -X PUT http://localhost:9200/{INDEX}/{TYPE}/{ID} -d ...
  function add($type, $id, $data){
   echo  $this->call($type . '/' . $id, array('method' => 'PUT', 'content' => $data));
  }

  //curl -X GET http://localhost:9200/{INDEX}/{TYPE}/_search?q= ...
  function query($type, $q){
    return $this->call($type . '/_search?' . http_build_query(array('q' => $q)));
  }
}

dann bin ich versucht, Indizes zu erstellen und einfach abrufen:

$this->load->library('elasticsearch');
                 $this->elasticsearch->index = 'comments';
                 $this->elasticsearch->create();
                 $data = '{author:jhon,datetime:2001-09-09 00:02:04}';
                 $this->elasticsearch->add($type ='details',$id = '1',$data);

wenn ich diesen code ausführen, zeigt es mir Fehler:

A PHP Error was encountered

Severity: Warning

Message: file_get_contents(http://localhost:9200/comments/) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request

Filename: libraries/Elasticsearch.php

Line Number: 19
A PHP Error was encountered

Severity: Notice

Message: file_get_contents() [function.file-get-contents]: Content-type not specified assuming application/x-www-form-urlencoded

Filename: libraries/Elasticsearch.php

Line Number: 19
A PHP Error was encountered

Severity: Warning

Message: file_get_contents(http://localhost:9200/comments/details/1) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request

Filename: libraries/Elasticsearch.php

Line Number: 19

tut, ich bin verwechselt/verpasst somenthing? sorry, aber ich bin Neuling über elasticsearch und auch ein wenig mit php 😛

verursachen, wenn ich gehe:

http://localhost:9200/comments/details/1

//it prints in window
 {"_index":"comments","_type":"details","_id":"1","exists":false}
  • ich möchte Fragen, wie zur Verwendung von Elastic Search mit CodeIgniter. und wie Sie in codeIgniter..
  • CI-Installations-link : ellislab.com/codeigniter/user-guide/installation dann ist u mit Bibliotheken wie in diesem github.com/confact/elasticsearch-codeigniter-library/blob/..., um die Schnittstelle Ihrer CI mit elastic search
  • ok thankx.. es könnte hilfreich für mich.
  • Sie sind herzlich willkommen!
  • Können wir den chat für ein paar Minuten.. wenn Sie Zeit haben.. ich muss Fragen über elasticsearch basic. 🙂
  • ich bin nicht sicher, ich kann Ihnen helfen, die Ursache der langen Zeit, die ich nicht mit elasticsearch ich wahrscheinlich vergessen, wie es zu benutzen 🙁

InformationsquelleAutor itsme | 2011-11-11
Schreibe einen Kommentar