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.
More info about Constant score query is in the official elasticsearch docs
Inside constant score query you can insert filter or query.
Lets take an example to write a constant score query with filter inside.
{
"constant_score" : {
"filter" : {
"term" : { "user" : "kimchy"}
},
"boost" : 1.2
}
}
And now the query via DSL:
$termFilter = new TermQuery("user", "kimchy");
$constantScoreQuery = new ConstantScoreQuery($termFilter, ["boost" => 1.2]);
$search = new Search();
$search->addQuery($constantScoreQuery);
$queryArray = $search->toArray();
To form a query with query inside is very easy, just add a query in ConstantScoreQuery constructor instead of filter.
{
"constant_score" : {
"query" : {
"term" : { "user" : "kimchy"}
},
"boost" : 1.2
}
}
via DSL:
$termQuery = new TermQuery("user", "kimchy");
$constantScoreQuery = new ConstantScoreQuery($termQuery, ["boost" => 1.2]);
$search = new Search();
$search->addQuery($constantScoreQuery);
$queryArray = $search->toArray();
How can I help you explore Laravel packages today?