Skip to content

new999day/elasticfantastic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#ElasticFantastic ##Библиотека ускоренной работы с запросами в ES

###Обычный запрос в ElasticSearch в стандартном клиенте:

// Аггрегация 20000 email пользователей с максимальным количеством документов в архиве с free_weeks=3 и возможностью сбора последнего ID объявления (MaxAggregation по ID)
$query = [
    'index' => 'adverts',
    'type' => 'advert',
    'from' => 0,
    'size' => 0,
    'body' => [
        'query' => [
            'bool' => [
                'must' => [
                    [
                        'term' => [
                            'system_data.storage_id' => [
                                'value' => 'archive',
                            ],
                        ],
                    ],
                    [
                        'term' => [
                            'system_data.free_weeks' => [
                                'value' => 3,
                            ],
                        ],
                    ],
                ],
            ],
        ],
        'aggs' => [
            'emails' => [
                'terms' => [
                    'field' => 'data.email',
                    'size' => 20000,
                ],
                'aggs' => [
                    'ids' => [
                        'max' => [
                            'field' => 'id',
                        ],
                    ],
                ],
            ],
        ],
        'sort' => [
            [
                'id' => 'desc',
            ],
        ],
    ],
    'fields' => [
        'id',
        'data.email',
    ],
];

$result = $this->getElasticSearch->search($query);

###Запрос при использовании ElasticFantastic

$result = ES::search('advert')
    ->query(
        ES::must(
            ES::term('system_data.storage_id', 'archive'),
            ES::term('system_data.free_weeks', 3)
        )
    )
    ->limit(0, 0)
    ->aggs(
        ES::aggs(
            ES::aggsTerm('emails', 'email', 20000),
            ES::aggs(
                ES::aggsMax('ids', 'id')
            )
        )
    )
    ->sort(['id' => 'desc'])
    ->fields(['id', 'data.email'])
    ->result();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages