Git Product home page Git Product logo

Comments (2)

spellord avatar spellord commented on May 28, 2024

I change string to text but now I get this error:
Exception: Could not convert [transaction.index] to boolean in [/var/www/apps/hbc/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php, line 174]

Exception: Could not convert [transaction.index] to boolean in [/var/www/apps/hbc/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php, line 174]
2018-05-11 01:25:59 Error: [Elastica\Exception\ResponseException] Could not convert [transaction.index] to boolean in /var/www/apps/hbc/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php on line 174
Stack Trace:
#0 /var/www/apps/hbc/vendor/ruflin/elastica/lib/Elastica/Request.php(171): Elastica\Transport\Http->exec(Object(Elastica\Request), Array)
#1 /var/www/apps/hbc/vendor/ruflin/elastica/lib/Elastica/Client.php(662): Elastica\Request->send()
#2 /var/www/apps/hbc/vendor/ruflin/elastica/lib/Elastica/Index.php(518): Elastica\Client->request('audit-logs/plan...', 'PUT', Array, Array)
#3 /var/www/apps/hbc/vendor/ruflin/elastica/lib/Elastica/Type.php(519): Elastica\Index->request('audit-logs/plan...', 'PUT', Array, Array)
#4 /var/www/apps/hbc/vendor/ruflin/elastica/lib/Elastica/Type/Mapping.php(272): Elastica\Type->request('planillapagos/_...', 'PUT', Array, Array)
#5 /var/www/apps/hbc/vendor/lorenzo/audit-stash/src/Shell/ElasticMappingShell.php(113): Elastica\Type\Mapping->send()
#6 /var/www/apps/hbc/vendor/cakephp/cakephp/src/Console/Shell.php(507): AuditStash\Shell\ElasticMappingShell->main(Object(App\Model\Table\PlanillapagosTable))
#7 /var/www/apps/hbc/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(230): Cake\Console\Shell->runCommand(Array, true, Array)
#8 /var/www/apps/hbc/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(182): Cake\Console\ShellDispatcher->_dispatch(Array)
#9 /var/www/apps/hbc/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(128): Cake\Console\ShellDispatcher->dispatch(Array)
#10 /var/www/apps/hbc/bin/cake.php(33): Cake\Console\ShellDispatcher::run(Array)
#11 {main}

Proposal solution:

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' => 'text', 'index' => 'false'],
        'type' => ['type' => 'text', 'index' => 'false'],
        'primary_key' => ['type' => 'text', 'index' => 'false'],
        'source' => ['type' => 'text', 'index' => 'false'],
        'parent_source' => ['type' => 'text', 'index' => 'false'],
        'original' => [
            'properties' => []
        ],
        'changed' => [
            'properties' => []
        ],
        'meta' => [
            'properties' => [
                'ip' => ['type' => 'text', 'index' => 'false'],
                'url' => ['type' => 'text', 'index' => 'false'],
                'user' => ['type' => 'text', 'index' => 'false'],
                'app_name' => ['type' => 'text', 'index' => 'false']
            ]
        ]
    ];

    $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;
}

Made this changes in lorenzo/audit-stash/src/Shell/ElasticMappingShell.php

from audit-stash.

spellord avatar spellord commented on May 28, 2024

I change not_analyzed to false and Fix but then I found other error with definition of integers and floats
https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html
in Php 7 64 bit integer value is out of the rage against the same definition in elasticsearch
int and float in eslasticsearch max and min values are 2exp31 and -2exp31
int and float in php7 64 bit max and min values are 2exp63 and -2exp63

Solution

protected function mapType($schema, $column)
{
    $baseType = $schema->baseColumnType($column);
    switch ($baseType) {
    case 'uuid':
        return ['type' => 'text', 'index' => 'false', 'null_value' => '_null_'];
    case 'integer':
        return ['type' => 'long', 'null_value' => ~PHP_INT_MAX];
    case 'date':
        return ['type' => 'date', 'format' => 'dateOptionalTime||basic_date||yyy-MM-dd', 'null_value' => '0001-01-01'];
    case 'datetime':
    case 'timestamp':
        return ['type' => 'date', 'format' => 'basic_t_time_no_millis||dateOptionalTime||basic_date_time||ordinal_date_time_no_millis||yyyy-MM-dd HH:mm:ss||basic_date', 'null_value' => '0001-01-01 00:00:00'];
    case 'float':
    case 'decimal':
        return ['type' => 'double', 'null_value' => ~PHP_INT_MAX];
    case 'float':
    case 'decimal':
        return ['type' => 'double', 'null_value' => ~PHP_INT_MAX];
    case 'boolean':
        return ['type' => 'boolean'];
    default:
        return [
            'type' => 'multi_field',
            'fields' => [
                $column => ['type' => 'text', 'null_value' => '_null_'],
                'raw' => ['type' => 'text', 'index' => 'false', 'null_value' => '_null_', 'ignore_above' => 256]
            ]
        ];
    }
}

This work for me change integer for long, float with double, string for text and not analyzed to false.
Made this changes in lorenzo/audit-stash/src/Shell/ElasticMappingShell.php

from audit-stash.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.