/** * @group functional */ public function testUpdateDocumentWithoutSource() { $index = $this->_createIndex(); $type = $index->getType('elastica_type'); $mapping = new Mapping(); $mapping->setProperties(array('name' => array('type' => 'string', 'store' => 'yes'), 'counter' => array('type' => 'integer', 'store' => 'no'))); $mapping->disableSource(); $type->setMapping($mapping); $newDocument = new Document(); $newDocument->setAutoPopulate(); $newDocument->set('name', 'Batman'); $newDocument->set('counter', 1); $type->addDocument($newDocument); $script = new Script('ctx._source.counter += count; ctx._source.name = name'); $script->setId($newDocument->getId()); $script->setParam('count', 2); $script->setParam('name', 'robin'); $script->setUpsert($newDocument); try { $type->updateDocument($script); $this->fail('Update request should fail because source is disabled. Fields param is not set'); } catch (ResponseException $e) { $error = $e->getResponse()->getError(); $this->assertContains('document_source_missing_exception', $error['type']); } $newDocument->setFieldsSource(); try { $type->updateDocument($newDocument); $this->fail('Update request should fail because source is disabled. Fields param is set to _source'); } catch (ResponseException $e) { $error = $e->getResponse()->getError(); $this->assertContains('document_source_missing_exception', $error['type']); } }