PHP code example of crowdskout / es-search-builder
1. Go to this page and download the library: Download crowdskout/es-search-builder 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/ */
use Crowdskout\EsSearchBuilder\Agg as AggBuilder;
use Crowdskout\EsSearchBuilder\Query;
der = new AggBuilder();
$agg = $aggBuilder->nested('parentField', $aggBuilder->terms('parentField.subField'));
$aggQuery = $agg->generateQuery();
use Crowdskout\EsSearchBuilder\Agg as AggBuilder;
use Crowdskout\EsSearchBuilder\Query;
use Elasticsearch\ClientBuilder;
// Build a query
$query = Query::terms('intField', [1, 2, 3, 4, 5, 6])
// Build an aggregation
$aggBuilder = new AggBuilder();
$agg = $aggBuilder->nested('parentField', $aggBuilder->terms('parentField.subField'));
// Initialize the Elasticsearch client
$client = ClientBuilder::create()->build()
// Run the search query
$params = [
'index' => 'my_index',
'type' => 'my_type',
'body' => [
'query' => $query,
'aggs' => $agg->generateQuery()
]
];
$response = $client->search($params);
// Parse the results
$parsedResult = $agg->generateResults($response['aggregations']);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.