-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
76 lines (66 loc) · 2.48 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
use ElastiCute\ElastiCute\Aggregation\AggregationBuilder;
use ElastiCute\ElastiCute\QueryBuilder;
require './vendor/autoload.php';
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
try {
$query = QueryBuilder::query()
->index('news_comments')
->groupMust(function (QueryBuilder $builder) {
$builder->whereTextContains('text', 'test');
$builder->whereGreaterThanOrEqual('@timestamp', '2021-12-05');
$builder->whereRaw([
'match' => [
'text' => 'test'
]
]);
})
->aggregations( function( AggregationBuilder $query ){
$query->make('like_count')->avg()->field('like_count');
$query->make('dislike_count')->avg()->field('dislike_count');
$query->make('dislike_count_term')->terms()->field('dislike_count')->additionalOptions(['size' => 3]);
} )
->select(['_id', '@timestamp', 'text'])
->get()
->getAggregations();
QueryBuilder::dieAndDump($query);
} catch (\ElastiCute\ElastiCute\ElastiCuteException $e) {
QueryBuilder::dieAndDump($e);
}
QueryBuilder::dieAndDump( $query );
try {
$query = QueryBuilder::query()
->index('instagram_profiles')
->sort([
'products.created_on' => [
'order' => 'desc',
],
])
->groupShould(function (QueryBuilder $builder) {
$builder->whereTextContains('name', 'payam1');
$builder->whereEqual('name', 'payam2');
})
->groupMust(function (QueryBuilder $builder) {
$builder->whereTextContains('name', 'payam7');
$builder->whereEqual('name', 'payam8');
$builder->groupMust(function (QueryBuilder $builder) {
$builder->whereTextNotContains('name', 'payam10');
$builder->whereEqual('name', 'mamad11');
});
$builder->whereNotEqual('name', 'payam13');
})
->whereNotEqual('currency', 'EUR2')
->select(['currency'])
->aggregations(function (AggregationBuilder $query) {
$query->make('like_count')->avg()->field('like_count');
$query->make('dislike_count')->avg()->field('dislike_count');
})
->get()
->map(function ($val) {
// do some stuff with $val
});
} catch (\ElastiCute\ElastiCute\ElastiCuteException $e) {
}
QueryBuilder::dieAndDump( $query );