Coder Social home page Coder Social logo

Bulk operations about elasticsearch-php HOT 8 CLOSED

elastic avatar elastic commented on September 23, 2024
Bulk operations

from elasticsearch-php.

Comments (8)

polyfractal avatar polyfractal commented on September 23, 2024

There are, please see the documentation here:

http://www.elasticsearch.org/guide/en/elasticsearch/client/php-api/current/_indexing_operations.html#_bulk_indexing

Currently, bulk requests must follow the Elasticsearch Bulk format. In the future, I would like to provide a helper method that builds the bulk format for you (because the syntax is kinda gross)

from elasticsearch-php.

insign avatar insign commented on September 23, 2024

It is terrible :(

from elasticsearch-php.

polyfractal avatar polyfractal commented on September 23, 2024

The bulk syntax was designed for performance, not developer friendliness.

Building the syntax algorithmically is very simple. And honestly, that is all a "helper" method would be doing. Here is some (untested) code to illustrate how simple it is:

//All your docs here
$myDocs = array( ... );  

// This will hold the final bulk
$bulkString = '';

// For brevity, assume docs don't have IDs
$action = array(
  "index" => new \stdClass()
);
$actionString = json_encode($action);

foreach ($myDocs as $doc) {
  $bulkString .= "$actionString\n";
  $bulkString .= json_encode($doc) . "\n";
}

$params['index'] = 'my_index';
$params['type']  = 'my_type';
$params['body']  = $bulkString

$ret = $client->bulk($params);

from elasticsearch-php.

insign avatar insign commented on September 23, 2024

Thank you @polyfractal . Have you idea when It will enter in the main code?

I will really try this. I want a bulk exactly for performace, but I don't think that it need be ugly.

from elasticsearch-php.

polyfractal avatar polyfractal commented on September 23, 2024

Unsure. There are a few bigger issues that I need to deal with first, not quite sure how long they will take.

Could you open a new ticket about the Bulk Helper method so that I don't forget?

from elasticsearch-php.

insign avatar insign commented on September 23, 2024

Sure! After the lunch!

from elasticsearch-php.

insign avatar insign commented on September 23, 2024

A fork (without unit tests) will be acceptable?

from elasticsearch-php.

polyfractal avatar polyfractal commented on September 23, 2024

Do you mean a Pull Request for the bulk helper function?

If yes, it should be implemented in a class outside of the client. The client is supposed to be entirely unopinionated...just a simple translation from the Elasticsearch API to a PHP API. I would recommend adding a new Helper class that lives in /src/Elasticsearch/Helper.php. Then users could do something like:

$helper = new Elasticsearch\Helper();
$helper->bulk()->index($myDoc);

I think there are a few functional requirements to make it useful:

  • index()
  • update()
  • delete()
  • create()
  • setIndex()
  • setType()
  • setBulkDocSize()
  • setBulkPhysicalSize()
  • setBulkTimeout()
  • flushBulk()

The bulk helper should also (probably?) return a special bulk object which facilitates working with the results (instead of just an array), so that it could have methods like:

  • getSucceeded()
  • getFailed()
  • getAll()
  • retryFailed()

You can see that the helper has quite a bit of functionality to make it really useful. All pretty simple, but a decent amount of code.

Test would be preferred before merging, but we can work on tests after some code has been produced.

from elasticsearch-php.

Related Issues (20)

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.