v-technologies/simpl-es

how to delete or update documents

Closed this issue · 3 comments

Hello,
Greate job with simpl-es ;). Could you tell me is there any possibility to:

  1. delete choosen document?
  2. update choosen document
  3. set id of my own

cheers

Hi,

To delete a doc :

Simples::current()->delete(YOUR_ID)->execute()

To update a doc :

$doc = Simples::current()->get(YOUR_ID)->execute()->document() ;
$doc->yourVar = 'new value' ;
Simples::current()->index($doc)->execute() ;

Note that actually Simples doesn't support the update API, it will reindex all your object.

To specify an id when indexing a doc :

$doc = array('your' => 'data') ;
Simples::current()->index($doc, array('id' => YOUR_SPECIFIC_ID))->execute() ;

If you are indexing multiple docs by passing an array of docs to index() (so Simples uses bulk index instead of simple index), you have to set the "id" key of each object at the first level of the object :

$docs = array(
  array('id' => 1, 'your' => 'data'),
  array('id' => 2, 'your' => 'other data')
);

I haven't tested this code while writing it but the idea is here. Tell me if it's ok or if you still have problems.

Cheers,
Sebastien

Thank you for your quick reply. Yesterday I've tested it and its working :).
If you want to update, you have to change object $doc to array and set id like this (I dont know (yet) how to put code)

code:
$doc = Simples::current()->get(YOUR_ID)->execute()->document() ;
$data = array(
'field'=> $doc->field,
'var'=> $doc->var
);
Simples::current()->index($doc, array('id'-> MY_ID))->execute();

and than it works.
Thank you for sharing your class and your effort. :)

The way i gave you should work, to update a doc since this commit :
60fecdf

I have used it in a project, so it should work for you too. If not, reopen the ticket I will have a look.

Thanks for using it ! ;)