makinacorpus / elasticsearch-query
ElasticSearch/OpenSearch 查询构建器
1.0.0-alpha3
2023-03-15 14:08 UTC
Requires
- php: >=8.0
Requires (Dev)
- phpunit/phpunit: ^9.6
This package is auto-updated.
Last update: 2024-09-08 16:10:08 UTC
README
这是一个非常小的 ElasticSearch 和 OpenSearch 查询构建器,主要围绕构建 bool 查询进行。
一个简单的例子
// Create a query. $query = new RootBoolQuery(); // Add some filters. $query->must()->term('statut', 20); // Create a nested bool query, for nested objects. $nested = $query->must()->createNestedBool('statut_histo'); $nested->must()->term('statut_histo.statut', 23); // Set some query options. $query->size(100); $query->from(0); $query->trackTotalHits(); // Add some sorts. $query->sort('pushed_at'); $query->sort('created_at'); \json_encode($query->build(), JSON_PRETTY_PRINT);
将生成以下 JSON
{ "query": { "bool": { "must": [ { "term": { "statut": 20 } }, { "nested": { "path": "statut_histo", "query": { "bool": { "must": { "term": { "statut_histo.statut": 23 } } } } } } ] } }, "from": 0, "size": 100, "track_total_hits": true, "sort": { "pushed_at": { "order": "asc" }, "created_at": { "order": "asc" } } }
可能以后会有更多文档。