Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Elasticsearch Dsl Laravel Package

ongr/elasticsearch-dsl

Object-oriented Elasticsearch query builder for PHP. Build searches, filters, aggregations and more with a DSL, then export to arrays for elasticsearch-php or ONGR ElasticsearchBundle. Supports Elasticsearch 5/6/7 via versioned releases.

View on GitHub
Deep Wiki
Context7

Aggregation

Objective aggregation builder represents all available Elasticsearch aggregations.

To form an aggregation you have to create Search object. See below an example of min aggregation usage.

$search = new Search();
$minAggregation = new MinAggregation('min_agg');
$minAggregation->setField('price');
$search->addAggregation($minAggregation);
$queryArray = $search->toArray();

There are 2 types of aggregation: bucketing and metric. The only difference in using them is that metric bucketing aggregations supports nesting while metric aggregations will ignore any set nested aggregations.

Nesting aggregations

Bucketing aggregation can have any number nested aggregations and nesting can go to unlimited depth.

Example nested aggregation.

{
    "aggregations": {
        "agg_color": {
            "terms": {
                "field": "color"
            },
            "aggregations": {
                "agg_avg_price": {
                    "avg": {
                        "field": "price"
                    }
                },
                "agg_brand": {
                    "terms": {
                        "field": "brand"
                    },
                    "aggregations": {
                        "agg_avg_price": {
                            "avg": {
                                "field": "price"
                            }
                        }
                    }
                }
            }
        },
        "agg_avg_price": {
            "avg": {
                "field": "price"
            }
        }
    }
}
$avgPriceAggregation = new AvgAggregation('avg_price');
$avgPriceAggregation->setField('price');

$brandTermAggregation = new TermsAggregation('brand');
$brandTermAggregation->setField('brand');
$brandTermAggregation->addAggregation($avgPriceAggregation);

$colorTermsAggregation = new TermsAggregation('color');
$colorTermsAggregation->setField('color');
$colorTermsAggregation->addAggregation($avgPriceAggregation);
$colorTermsAggregation->addAggregation($brandTermAggregation);

$search = new Search();
$search->addAggregation($colorTermsAggregation);
$search->addAggregation($avgPriceAggregation);

$queryArray = $search->toArray();

Metric Aggregations

Bucketing Aggregations

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle