本文整理汇总了PHP中Elastica\Type\Mapping::send方法的典型用法代码示例。如果您正苦于以下问题:PHP Mapping::send方法的具体用法?PHP Mapping::send怎么用?PHP Mapping::send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Type\Mapping
的用法示例。
在下文中一共展示了Mapping::send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetIdNoSource
public function testGetIdNoSource()
{
// Creates a new index 'xodoa' and a type 'user' inside this index
$indexName = 'xodoa';
$typeName = 'user';
$client = $this->_getClient();
$index = $client->getIndex($indexName);
$index->create(array(), true);
$type = $index->getType($typeName);
$mapping = new Mapping($type);
$mapping->disableSource();
$mapping->send();
// Adds 1 document to the index
$docId = 3;
$doc1 = new Document($docId, array('username' => 'hans'));
$type->addDocument($doc1);
// Refreshes index
$index->refresh();
$resultSet = $type->search('hans');
$this->assertEquals(1, $resultSet->count());
$result = $resultSet->current();
$this->assertEquals(array(), $result->getSource());
$this->assertInstanceOf('Elastica\\Result', $result);
$this->assertEquals($indexName, $result->getIndex());
$this->assertEquals($typeName, $result->getType());
$this->assertEquals($docId, $result->getId());
$this->assertGreaterThan(0, $result->getScore());
$this->assertInternalType('array', $result->getData());
}
示例2: _getTestIndex
protected function _getTestIndex()
{
$index = $this->_createIndex('has_child_test');
$parentType = $index->getType('parent');
$childType = $index->getType('child');
$childMapping = new Mapping($childType);
$childMapping->setParent('parent');
$childMapping->send();
$altType = $index->getType('alt');
$altDoc = new Document('alt1', array('name' => 'altname'));
$altType->addDocument($altDoc);
$parent1 = new Document('parent1', array('id' => 'parent1', 'user' => 'parent1', 'email' => 'parent1@test.com'));
$parentType->addDocument($parent1);
$parent2 = new Document('parent2', array('id' => 'parent2', 'user' => 'parent2', 'email' => 'parent2@test.com'));
$parentType->addDocument($parent2);
$child1 = new Document('child1', array('id' => 'child1', 'user' => 'child1', 'email' => 'child1@test.com'));
$child1->setParent('parent1');
$childType->addDocument($child1);
$child2 = new Document('child2', array('id' => 'child2', 'user' => 'child2', 'email' => 'child2@test.com'));
$child2->setParent('parent2');
$childType->addDocument($child2);
$child3 = new Document('child3', array('id' => 'child3', 'user' => 'child3', 'email' => 'child3@test.com', 'alt' => array(array('name' => 'testname'))));
$child3->setParent('parent2');
$childType->addDocument($child3);
$index->refresh();
return $index;
}
示例3: validate
/**
* @return Status
*/
public function validate()
{
$this->outputIndented("Validating mappings...");
if ($this->optimizeIndexForExperimentalHighlighter && !in_array('experimental highlighter', $this->availablePlugins)) {
$this->output("impossible!\n");
return Status::newFatal(new RawMessage("wgCirrusSearchOptimizeIndexForExperimentalHighlighter is set to true but the " . "'experimental highlighter' plugin is not installed on all hosts."));
}
$requiredMappings = $this->mappingConfig;
if (!$this->checkMapping($requiredMappings)) {
/** @var Mapping[] $actions */
$actions = array();
// TODO Conflict resolution here might leave old portions of mappings
foreach ($this->types as $typeName => $type) {
$action = new Mapping($type);
foreach ($requiredMappings[$typeName] as $key => $value) {
$action->setParam($key, $value);
}
$actions[] = $action;
}
try {
foreach ($actions as $action) {
$action->send();
}
$this->output("corrected\n");
} catch (ExceptionInterface $e) {
$this->output("failed!\n");
$message = ElasticsearchIntermediary::extractMessage($e);
return Status::newFatal(new RawMessage("Couldn't update mappings. Here is elasticsearch's error message: {$message}\n"));
}
}
return Status::newGood();
}
示例4: sendMapping
/**
* @param \Elastica\Index $index
* @param string $mappingName
* @param array $mappingData
*
* @return void
*/
protected function sendMapping(Index $index, $mappingName, array $mappingData)
{
$type = $index->getType($mappingName);
$this->messenger->info(sprintf('Send mapping type "%s" (index: "%s")', $mappingName, $index->getName()));
$mapping = new Mapping($type);
foreach ($mappingData as $key => $value) {
$mapping->setParam($key, $value);
}
$mapping->send();
}
示例5: postInstall
public function postInstall(RecordInterface $record)
{
$client = new Client(array('host' => $this->registry['search.host'], 'port' => $this->registry['search.port']));
$index = $client->getIndex('amun');
$index->create();
$type = $index->getType('page');
$mapping = new Mapping();
$mapping->setType($type);
$mapping->setProperties(array('id' => array('type' => 'string', 'include_in_all' => false), 'userId' => array('type' => 'integer', 'include_in_all' => false), 'path' => array('type' => 'string', 'include_in_all' => true), 'title' => array('type' => 'string', 'include_in_all' => true), 'content' => array('type' => 'string', 'include_in_all' => true), 'date' => array('type' => 'date', 'include_in_all' => false)));
$mapping->send();
}
示例6: getType
/**
* @return Type
*/
private function getType()
{
if (null === $this->type) {
$this->type = $this->getIndex()->getType($this->typeName);
$mapping = new Type\Mapping();
$mapping->setType($this->type);
$mapping->setTtl(['enabled' => true]);
$mapping->setProperties([self::ID_FIELD => ['type' => 'string', 'include_in_all' => true], self::VALUE_FIELD => ['type' => 'string', 'include_in_all' => true]]);
$mapping->send();
}
return $this->type;
}
示例7: create
/**
* Create the mapping for the type.
*
* @param \Cake\Datasource\ConnectionInterface $db The Elasticsearch connection
* @return void
*/
public function create(ConnectionInterface $db)
{
if (empty($this->schema)) {
return;
}
$index = $db->getIndex();
if (!$index->exists()) {
$index->create();
}
$type = $index->getType($this->table);
$mapping = new ElasticaMapping();
$mapping->setType($type);
$mapping->setProperties($this->schema);
$mapping->send();
$this->created[] = $db->configName();
}
示例8: main
/**
* Creates the elastic search mapping for the provided table, or just prints it out
* to the screen if the `dry-run` option is provided.
*
* @param string $table The table name to inspect and create a mapping for
* @return bool
*/
public function main($table)
{
$table = TableRegistry::get($table);
$schema = $table->schema();
$mapping = ['@timestamp' => ['type' => 'date', 'format' => 'basic_t_time_no_millis||dateOptionalTime||basic_date_time||ordinal_date_time_no_millis||yyyy-MM-dd HH:mm:ss'], 'transaction' => ['type' => 'string', 'index' => 'not_analyzed'], 'type' => ['type' => 'string', 'index' => 'not_analyzed'], 'primary_key' => ['type' => 'string', 'index' => 'not_analyzed'], 'source' => ['type' => 'string', 'index' => 'not_analyzed'], 'parent_source' => ['type' => 'string', 'index' => 'not_analyzed'], 'original' => ['properties' => []], 'changed' => ['properties' => []], 'meta' => ['properties' => ['ip' => ['type' => 'string', 'index' => 'not_analyzed'], 'url' => ['type' => 'string', 'index' => 'not_analyzed'], 'user' => ['type' => 'string', 'index' => 'not_analyzed'], 'app_name' => ['type' => 'string', 'index' => 'not_analyzed']]]];
$properties = [];
foreach ($schema->columns() as $column) {
$properties[$column] = $this->mapType($schema, $column);
}
if ($table->hasBehavior('AuditLog')) {
$whitelist = (array) $table->behaviors()->AuditLog->config('whitelist');
$blacklist = (array) $table->behaviors()->AuditLog->config('blacklist');
$properties = empty($whitelist) ? $properties : array_intersect_key($properties, array_flip($whitelist));
$properties = array_diff_key($properties, array_flip($blacklist));
}
$mapping['original']['properties'] = $mapping['changed']['properties'] = $properties;
$client = ConnectionManager::get('auditlog_elastic');
$index = $client->getIndex(sprintf($client->getConfig('index'), '-' . gmdate('Y.m.d')));
$type = $index->getType($table->table());
$elasticMapping = new ElasticaMapping();
$elasticMapping->setType($type);
$elasticMapping->setProperties($mapping);
if ($this->params['dry-run']) {
$this->out(json_encode($elasticMapping->toArray(), JSON_PRETTY_PRINT));
return true;
}
if ($this->params['use-templates']) {
$template = ['template' => sprintf($client->getConfig('index'), '*'), 'mappings' => $elasticMapping->toArray()];
$response = $client->request('_template/template_' . $type->getName(), Request::PUT, $template);
$this->out('<success>Successfully created the mapping template</success>');
return $response->isOk();
}
if (!$index->exists()) {
$index->create();
}
$elasticMapping->send();
$this->out('<success>Successfully created the mapping</success>');
return true;
}
示例9: store
/**
* {@inheritdoc}
*/
public function store(array $data, array $keys, $namespace)
{
$type = $this->index->getType($namespace);
// Build mapping
$mapping = new Mapping();
$mapping->setType($type);
$mapping->setProperties(array('hash' => array('type' => 'string', 'include_in_all' => true), 'keys' => array('type' => 'string', 'include_in_all' => true)));
$mapping->send();
// Build document
$document = new Document('', array_merge($data, array('hash' => $this->getHash($data, $keys), 'keys' => $keys)));
$type->addDocument($document);
$this->index->refresh();
}
示例10: createType
/**
* {@inheritDoc}
*/
public function createType(ClassMetadata $metadata)
{
$type = $this->getIndex($metadata->index)->getType($metadata->type);
$properties = $this->getMapping($metadata->fieldMappings);
$rootProperties = $this->getRootMapping($metadata->rootMappings);
$mapping = new Mapping($type, $properties);
$mapping->disableSource($metadata->source);
if (isset($metadata->boost)) {
$mapping->setParam('_boost', array('name' => '_boost', 'null_value' => $metadata->boost));
}
if (isset($metadata->parent)) {
$mapping->setParent($metadata->parent);
}
foreach ($rootProperties as $key => $value) {
$mapping->setParam($key, $value);
}
$mapping->send();
return $type;
}
示例11: setMapping
/**
* @param array $mappingArray
* @param Elastica\Type $type
*/
protected function setMapping(array $mappingArray, Elastica\Type $type)
{
try {
$mapping = new Elastica\Type\Mapping();
$mapping->setType($type);
$mapping->setProperties($mappingArray);
$mapping->send();
} catch (\Exception $e) {
$this->outputLine('Could not add mapping for type ' . $type->getName() . '. Message was ' . $e->getMessage());
}
}
示例12: analysis
/**
* Create Elastica Analysis.
*
* @param object $index Elastica Index
* @param array $posttypes Array containing all post types
* @param array $terms Array containing all terms
* @return object $index Elastica Index
*
* @since 3.0.0
*/
protected function analysis($index, $posttypes, $terms)
{
//Check integrity
if (empty($index)) {
return null;
}
//Check integrity
if (empty($posttypes) && empty($terms)) {
return null;
}
//Define properties
$props = array('id' => array('type' => 'integer', 'include_in_all' => false), 'tags' => array('type' => 'string', 'index' => 'analyzed'), 'parent' => array('type' => 'integer', 'index' => 'analyzed'), 'title' => array('type' => 'string', 'index' => 'analyzed'), 'content' => array('type' => 'string', 'index' => 'analyzed'), 'excerpt' => array('type' => 'string', 'index' => 'analyzed'), 'author' => array('type' => 'integer', 'index' => 'analyzed'), 'date' => array('type' => 'date', 'format' => 'date_time_no_millis'), 'tags_suggest' => array('type' => 'completion', 'analyzer' => 'simple', 'search_analyzer' => 'simple', 'payloads' => false), '_boost' => array('type' => 'float', 'include_in_all' => false));
/**
* Update props analysis.
*
* @param array $props
*
* @since 3.3.0
*/
do_action('tto_plugin_search_analysis', $props);
//Set analysis
if (isset($posttypes) && !empty($posttypes)) {
foreach ($posttypes as $k) {
if (empty($k)) {
continue;
}
$index->create(array('number_of_shards' => 4, 'number_of_replicas' => 1, 'analysis' => array('analyzer' => array('indexAnalyzer' => array('type' => 'custom', 'tokenizer' => 'standard', 'filter' => array('lowercase', 'asciifolding', 'filter_' . $k)), 'searchAnalyzer' => array('type' => 'custom', 'tokenizer' => 'standard', 'filter' => array('standard', 'lowercase', 'asciifolding', 'filter_' . $k))), 'filter' => array('filter_' . $k => array('type' => 'standard', 'language' => TTO_LOCAL, 'ignoreCase' => true)))), true);
//Define new Type
$type = $index->getType($k);
//Define a new Elastica Mapper
$mapping = new Mapping();
$mapping->setType($type);
//$mapping->setParam('analyzer', 'indexAnalyzer');
//$mapping->setParam('search_analyzer', 'searchAnalyzer');
//Define boost field
/*$mapping->setParam('_boost', array(
'name' => '_boost',
'null_value' => 1.0
));*/
//Set mapping
$mapping->setProperties($props);
//Send mapping to type
$mapping->send();
}
}
//Set analysis
if (isset($terms) && !empty($terms)) {
foreach ($terms as $t) {
if (empty($t)) {
continue;
}
$index->create(array('number_of_shards' => 4, 'number_of_replicas' => 1, 'analysis' => array('analyzer' => array('indexAnalyzer' => array('type' => 'custom', 'tokenizer' => 'standard', 'filter' => array('lowercase', 'asciifolding', 'filter_' . $t)), 'searchAnalyzer' => array('type' => 'custom', 'tokenizer' => 'standard', 'filter' => array('standard', 'lowercase', 'asciifolding', 'filter_' . $t))), 'filter' => array('filter_' . $t => array('type' => 'standard', 'language' => TTO_LOCAL, 'ignoreCase' => true)))), true);
//Define new Type
$type = $index->getType($t);
//Define a new Elastica Mapper
$mapping = new Mapping();
$mapping->setType($type);
$mapping->setParam('index_analyzer', 'indexAnalyzer');
$mapping->setParam('search_analyzer', 'searchAnalyzer');
//Define boost field
$mapping->setParam('_boost', array('name' => '_boost', 'null_value' => 1.0));
//Set mapping
$mapping->setProperties($props);
// Send mapping to type
$mapping->send();
}
}
//Return index
return $index;
}
示例13: create
/**
* Creates the index and sets the mapping for this type.
*
* @param bool $recreate OPTIONAL Recreates the index if true (default = false)
*/
public function create($recreate = false)
{
$this->getIndex()->create($this->_indexParams, $recreate);
$mapping = new Mapping($this->getType());
$mapping->setProperties($this->_mapping);
$mapping->setSource(array('enabled' => $this->_source));
$mapping->send();
}
示例14: createMappings
/**
* Define all known mappings
*/
protected function createMappings(\Elastica\Index $index)
{
foreach ($this->getIndexedClasses() as $class) {
/** @var $sng Searchable */
$sng = singleton($class);
$type = $sng->getElasticaType();
if (isset($this->mappings[$type])) {
// captured later
continue;
}
$mapping = $sng->getElasticaMapping();
$mapping->setType($index->getType($type));
$mapping->send();
}
if ($this->mappings) {
foreach ($this->mappings as $type => $fields) {
$mapping = new Mapping();
$mapping->setProperties($fields);
$mapping->setParam('date_detection', false);
$mapping->setType($index->getType($type));
$mapping->send();
}
}
}
示例15: function
/**
* Created by PhpStorm.
* User: Jiang Yu
* Date: 2016/04/22
* Time: 16:11.
*/
use Elastica\Type\Mapping;
use ESGateway\DataModel\FieldMapping\MappingFactory;
require __DIR__ . '/../../bootstrap.php';
$createMappingHandler = function (\Elastica\Type $type) {
$mapping = new Mapping();
$mapping->setType($type);
$mappingProperties = (new MappingFactory())->make();
$mapping->setProperties($mappingProperties);
$response = $mapping->send();
dump('create default mapping');
dump($response);
};
$options = getopt('', ['gv:', 'index:', 'createIndex:']);
$client = new \Elastica\Client(['host' => ELASTIC_SEARCH_HOST, 'port' => ELASTIC_SEARCH_PORT]);
if (isset($options['createIndex'])) {
$indexName = trim($options['createIndex']);
assert(is_string($indexName) && strlen($indexName) > 0 && strpos($indexName, 'farm_v') === 0, 'bad index name');
$index = $client->getIndex($indexName);
$exists = $index->exists();
if (!$exists) {
$response = $index->create();
dump('create index');
dump($response);
}