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

Bool query

More info about Bool query is in the official elasticsearch docs

It's a query that matches documents matching boolean combinations of other queries.

To create a bool query unlike other queries you don't have to create BoolQuery object. Just add queries to the search object and it will form bool query automatically.

Lets take an example to write a bool query with Elasticsearch DSL.

{
    "bool" : {
        "must" : {
            "term" : { "user" : "kimchy" }
        },
        "must_not" : {
            "range" : {
                "age" : { "from" : 10, "to" : 20 }
            }
        },
        "should" : [
            {
                "term" : { "tag" : "wow" }
            },
            {
                "term" : { "tag" : "elasticsearch" }
            }
        ],
        "minimum_should_match" : 1,
        "boost" : 1.0
    }
}

And now the query via DSL:

$termQueryForUser = new TermQuery("user", "kimchy");
$termQueryForTag1 = new TermQuery("tag", "wow");
$termQueryForTag2 = new TermQuery("tag", "elasticsearch");
$rangeQuery = new RangeQuery("age", ["from" => 10, "to" => 20]);

$bool = new BoolQuery();
$bool->addParameter("minimum_should_match", 1);
$bool->addParameter("boost", 1);
$bool->add($termQueryForUser, BoolQuery::MUST);
$bool->add($rangeQuery, BoolQuery::MUST_NOT);
$bool->add($termQueryForTag1, BoolQuery::SHOULD);
$bool->add($termQueryForTag2, BoolQuery::SHOULD);

$search = new Search();
$search->addQuery($bool);

$queryArray = $search->toArray();

There is also an exception due adding queries to the search. If you add only one query without type it will form simple query. e.g. lets try to create match all query.

$search = new Search();
$matchAllQuery = new MatchAllQuery();
$search->addQuery($matchAllQuery);
$queryArray = $search->toArray();

You will get this query:

{
    "query": {
        "match_all": {}
    }
}

More info about Search look in the How to search chapter.

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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui