PHP code example of andares / freedsl

1. Go to this page and download the library: Download andares/freedsl library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

andares / freedsl example snippets


$index   = 'myindex-*';
$type    = 'some_entity';
$builder = new FreeDSL\Builder($index, $type);

$builder->id = $id;
$result = $client->get($builder());

$builder->body = [
  'query' => [
    'match' => ['name' => $name],
  ],
];
$result = $client->search($builder());

$builder->body()
  ->query()->bool()
    ->must()
      ->term(['user.name' => $name]);
$result = $client->search($builder());

$builder
  ->body()->query()->bool()->must()
    ->match_phrase()
    ->body_field()
    ->query('room/enter')
  ->body()->query()->bool()->must()
    ->range()
    ->named('@timestamp', [
      'gte'       => $start_time,
      'lt'        => $end_time,
      'format'    => 'yyyy-MM-dd',
      'time_zone' => '+08:00',
    ]);

$builder
  ->body()->aggs()->watch_count()
    ->terms()
    ->field('response.data.master.id')
  ->body()->aggs()->watch_count()
    ->terms()
    ->size($limit);

$builder->body()
    ->sort(['@timestamp' => 'desc'])
  ->body()
    ->from(0)
  ->body()
    ->size(1);

$dsl = $builder();
// ...执行查询