Code Monkey home page Code Monkey logo

elasticsearch's Introduction

Soupmix

Latest Stable Version Total Downloads Latest Unstable Version License Scrutinizer Code Quality Build Status Coverage Status

Simple ElasticSearch abstraction layer adapter to handle CRUD operations written in PHP. This library does not provide any ORM or ODM.

Installation

It's recommended that you use Composer to install Soupmix.

$ composer require soupmix/elasticsearch "~0.8"

This will install Soupmix and all required dependencies. Soupmix requires PHP 7.1 or newer, elasticsearch-php library or newer for Elasticsearch

Documentation

API Documentation: See details about the db adapters functions:

Usage


// Connect to Elasticsearch Service
$adapter_config             = [];
$adapter_config['db_name']  = 'indexname';
$adapter_config['hosts']    = ["127.0.0.1:9200"];
$adapter_config['options']  = [];
$config['db_name'] = $adapter_config['db_name];
$client = \Elasticsearch\ClientBuilder::create()->setHosts($adapter_config['hosts'])->build();

$e=new Soupmix\ElasticSearch($config, $client);

$docs = [];
$docs[] = [
    "full_name" => "John Doe",
      "age" => 33,
      "email"    => "[email protected]",
      "siblings"=> [
        "male"=> [
          "count"=> 1,
          "names"=> ["Jack"]
        ],
        "female"=> [
          "count" => 1,
          "names" =>["Jane"]
        ]      
      ]
];
$docs[] = [
    "full_name" => "Jack Doe",
      "age" => 38,
      "email"    => "[email protected]",
      "siblings"=> [
        "male"=> [
          "count"=> 1,
          "names"=> ["John"]
        ],
        "female"=> [
          "count" => 1,
          "names" =>["Jane"]
        ]      
      ]
];

$docs[] = [
    "full_name" => "Jane Doe",
      "age" => 29,
      "email"    => "[email protected]",
      "siblings"=> [
        "male"=> [
          "count"=> 2,
          "names"=> ["Jack","John"]
        ],
        "female"=> [
          "count" => 0,
          "names" =>[]
        ]      
      ]
];

foreach($docs as $doc){
    // insert user into database
    $es_user_id = $e->insert("users",$doc);

}
// get user data using id
$es_user_data = $e->get('users', "AVPHZO1DY8UxeHDGBhPT");


$filter = ['age_gte'=>0];
// update users' data that has criteria encoded in $filter
$set = ['is_active'=>1,'is_deleted'=>0];

$e->update("users",$)

$filter = ["siblings.male.count__gte"=>2];

//delete users that has criteria encoded in $filter
$e->delete('users', $filter);



// user's age lower_than_and_equal to 34 or greater_than_and_equal 36 but not 38
$filter=[[['age__lte'=>34],['age__gte'=>36]],"age__not"=>38];

//find users that has criteria encoded in $filter
$docs = $e->find("users", $filter);


Contribute

  • Open issue if found bugs or sent pull request.
  • Feel free to ask if you have any questions.

elasticsearch's People

Contributors

hkulekci avatar mkorkmaz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

c-daney

elasticsearch's Issues

How can I build a MatchAll query with soupmix

There is a confusion while creating a match_all query. I want to get all my documents in an index or type.

Below script is not work :(

$results = $this->client->find('test', null, null, ['id' => 'desc']);

Find method return following error in this case

$modifiedCount = $this->client->update('test', ['title' => 'test'], ['title' => 'test2']);
$this->assertTrue($modifiedCount >= 1);

Error:

Undefined index: fields

/Volumes/webroot/github/elasticsearch-1/src/ElasticSearch.php:225
/Volumes/webroot/github/elasticsearch-1/src/ElasticSearch.php:109
/Volumes/webroot/github/elasticsearch-1/tests/ElasticsearchTest.php:73

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.