cakephp / elastic-search

Elastic search datasource for CakePHP
Other
88 stars 53 forks source link

failed to parse error (id) #105

Closed lilHermit closed 8 years ago

lilHermit commented 8 years ago

If I pull a record from ES and edit it all is fine, however if I create a new entity save it, modify it and resave I get "failed to parse". From my debugging I believe https://github.com/cakephp/elastic-search/blob/master/src/Type.php#L473 should read "unset($data['id']);"

working example (fetch and save)

$menuItemType = TypeRegistry::get('MenuItems');

$menuItem = $menuItemType->find()->firstOrFail();
$menuItem->content = "changed content";
$menuItemType->save($menuItem);

Failing example (new, save and resave)

$menuItemType = TypeRegistry::get('MenuItems');
$menuItem = $menuItemType->newEntity();
$menuItem->action = 'Do something';
$menuItemType->save($menuItem);

$menuItem->content = 'Some content';
$menuItemType->save($menuItem);
lilHermit commented 8 years ago

On further investigation it is a double save that causes the Exception too.

$menuItemType = TypeRegistry::get('MenuItems');
$menuItem = $menuItemType->find()->firstOrFail();
$menuItem->content = "changed content";
$menuItemType->save($menuItem);
$menuItemType->save($menuItem);
            
lilHermit commented 8 years ago

The issue does seem to be caused by meta values like id and _version in the body of the PUT request

markstory commented 8 years ago

Closing as a pull request is open now.