Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/3.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Stenvall committed Aug 21, 2018
2 parents 3f94d23 + a5d0074 commit 2895b68
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 27 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,16 @@

All notable changes to this project will be documented in this file.

## [3.3.0] - 2018-0821

- Added a console command for updating certain dynamic index settings

## [3.2.0] - 2018-06-18

- Added support for setting min_doc_count on term aggregations
- Added support for setting scripted fields and stored fields
- Fix an issue with empty function_score queries

## [3.1.0] - 2018-05-22

- Fixed omitting "from" in queries where it's not needed
Expand Down
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -307,6 +307,11 @@ If your documents are very large you may want to decrease the batch size used du
Elasticsearch from running out of memory. You can do so by passing `--batchSize=X` to the `elastic:migrations:migrate`
command. If the option is omitted, the default value of 1000 is used.

## Updating dynamic index settings

There is a console command (`elastic:index:settings:update`) that you can use to update certain dynamic index settings
such as the refresh interval or the number of replicas. Simply register it in your console kernel to start using it.

## Contributing

Please read the [guidelines](.github/CONTRIBUTING.md).
Expand Down
77 changes: 77 additions & 0 deletions src/Console/UpdateIndexSettingsCommand.php
@@ -0,0 +1,77 @@
<?php

namespace Nord\Lumen\Elasticsearch\Console;

use Illuminate\Console\Command;
use Nord\Lumen\Elasticsearch\Contracts\ElasticsearchServiceContract;

/**
* Class SetIndexSettingsCommand
* @package namespace Nord\Lumen\Elasticsearch\Console
*/
class UpdateIndexSettingsCommand extends Command
{

/**
* @var string
*/
protected $signature = 'elastic:index:settings:update
{ index : The name of the index to update }
{--numReplicas= : The value of index.refresh_interval that should be set }
{--refreshInterval= : The value of index.refresh_interval that should be set }';

/**
* @var string
*/
protected $description = 'Updates specified dynamic index settings for the specified index';

/**
* @var ElasticsearchServiceContract
*/
private $elasticsearchService;

/**
* SetIndexSettingsCommand constructor.
*
* @param ElasticsearchServiceContract $elasticsearchService
*/
public function __construct(ElasticsearchServiceContract $elasticsearchService)
{
parent::__construct();

$this->elasticsearchService = $elasticsearchService;
}

public function handle(): void
{
$index = $this->input->getArgument('index');
$numReplicas = $this->input->getOption('numReplicas');
$refreshInterval = $this->input->getOption('refreshInterval');

$settings = [];

if ($numReplicas !== null) {
$settings['number_of_replicas'] = (int)$numReplicas;
}

if ($refreshInterval !== null) {
$settings['refresh_interval'] = $refreshInterval;
}

if (!empty($settings)) {
$this->putIndexSettings($index, $settings);
}
}

/**
* @param string $index
* @param array $settings
*/
private function putIndexSettings(string $index, array $settings): void
{
$this->elasticsearchService->indices()->putSettings([
'index' => $index,
'body' => $settings,
]);
}
}
35 changes: 32 additions & 3 deletions src/Search/Aggregation/Bucket/TermsAggregation.php
Expand Up @@ -11,12 +11,41 @@ class TermsAggregation extends AbstractAggregation
{
use HasField;

/**
* @var int
*/
protected $minDocCount;

/**
* @return int|null
*/
public function getMinDocCount(): ?int
{
return $this->minDocCount;
}

/**
* @param int $minDocCount
*/
public function setMinDocCount(int $minDocCount)
{
$this->minDocCount = $minDocCount;

return $this;
}

public function toArray()
{
return [
$data = [
'terms' => [
'field' => $this->getField()
]
'field' => $this->getField(),
],
];

if (!empty($this->getMinDocCount())) {
$data['terms']['min_doc_count'] = $this->getMinDocCount();
}

return $data;
}
}
2 changes: 1 addition & 1 deletion src/Search/Query/Compound/FunctionScoreQuery.php
Expand Up @@ -59,7 +59,7 @@ public function toArray()
if (!empty($queryArray)) {
$array['query'] = $queryArray;
} else {
$array['query'] = ['match_all' => []];
$array['query'] = ['match_all' => new \stdClass()];
}
}

Expand Down

0 comments on commit 2895b68

Please sign in to comment.