Code Monkey home page Code Monkey logo

elasticsearch-codeigniter-library's Introduction

elasticsearch-codeigniter-library

A small library to make search queries and create and add indexes.

How to index data with the library

You create data in an array to pass it to elasticsearch. You probably want to specify the Key for the document and show the result. Like this:

$id = 1337;
$data = array("name"=>"nisse", "age"=>"14", "sex"=>"male");
var_dump($this->elasticsearch->add("people", $id, $data));

This will save the array to the elasticsearch. "people" is the collection, the index where you want to save it.

CRUD Operations

CREATE

$id = 1337;
$data = array("name"=>"nisse", "age"=>"14", "sex"=>"male");
$return = $this->elasticsearch->add("people", $id, $data);

READ

$id = 1337;
$this->elasticsearch->get("people", $id);

UPDATE

$id = 1337;
$data = array(
	"id" => $id,
	"name"=>"nisse", 
	"age"=>"14", 
	"sex"=>"male"
);
$return = $this->elasticsearch->add("people", $id, $data);

DELETE

$id = 1337;
$this->elasticsearch->delete("people", $id);

elasticsearch-codeigniter-library's People

Contributors

confact avatar silas-ss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

elasticsearch-codeigniter-library's Issues

More detailed usage

Hello there,

Thanks for wrapping up this library. Except the add method, it is not clear how to get the most of the other methods

Is it possible to make an analogy curl commands vs this library ?

Thanks

The configuration file elasticsearch does not exist

hello,

i try you library recently, and i found error.
i guess you forget to add elasticsearch configuration file in config.php

because as long as i knew, you only add this in config.php

//config for elastic search
$config['es_server'] = 'http://localhost:9200';
$config['index'] = '';

and the , in your library file, you load this :

$ci = &get_instance();
$ci->config->load("elasticsearch");
$this->server = $ci->config->item('es_server');
$this->index = $ci->config->item('index');

its never work dude.
i take out the $ci->config->load("elasticsearch") section.

Rewrite to not depend on cURL?

There is an offical way of a PHP class, full example from website is quoted:

$esclient = Elasticsearch\ClientBuilder::create()
              ->setHosts(["localhost:9200"])
              ->build();
$params = [
'index' => 'social-*',
'body' => [
    'query' => [
        'match' => [ 'message' => 'myProduct' ]
    ],
    'aggs' => [
        'top_10_states' => [
            'terms' => [
                'field' => 'state',
                'size' => 10,
            ]
        ]
    ]
]
];
$response = $esclient->search($params);

Documentation:
https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html

is there update method?

This is how i understand this work.

Say I have a blog, when I click save the blog post. I will use the add method to add data to the index. Something like this

$data = array("title"=>$title, "detail"=>$detail);
$this->elasticsearch->add("listing", $id, $data);

Then a while later I decide to edit the post, I think I would to need to update the entry I added before. Something like this

$data = array("title"=>$title, "detail"=>$detail);
$this->elasticsearch->update("listing", $id, $data);

Isn't that right? Because I see no update method in the lib. I'm new to this search stuff, so let me know if I'm wrong.

Set dependency to elastic/elasticsearch

Github allows project-dependencies. You may wish to setup one to elastic/elasticsearch as this project is related to it (requires, else the search won't work).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.