本文整理汇总了PHP中Elastica\Script::setId方法的典型用法代码示例。如果您正苦于以下问题:PHP Script::setId方法的具体用法?PHP Script::setId怎么用?PHP Script::setId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Script
的用法示例。
在下文中一共展示了Script::setId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testUpdateDocumentWithoutSource
/**
* @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']);
}
}