From 801803ce6a83b2ce0ac815a88e0d2734aaf09fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simonas=20=C5=A0erlinskas?= <simonas.serlinskas@nfq.com> Date: Fri, 9 Mar 2018 14:50:50 +0200 Subject: [PATCH] Changes to support ES 6 --- README.md | 14 +-- composer.json | 12 +- docs/Aggregation/{ => Bucketing}/Children.md | 0 .../{ => Bucketing}/DateHistogram.md | 0 docs/Aggregation/{ => Bucketing}/DateRange.md | 0 .../Bucketing/DiversifiedSampler.md | 0 docs/Aggregation/{ => Bucketing}/Filter.md | 0 docs/Aggregation/{ => Bucketing}/Filters.md | 0 .../{ => Bucketing}/GeoDistance.md | 0 .../{ => Bucketing}/GeoHashGrid.md | 0 docs/Aggregation/{ => Bucketing}/Global.md | 0 docs/Aggregation/{ => Bucketing}/Histogram.md | 0 docs/Aggregation/{ => Bucketing}/Ipv4Range.md | 0 docs/Aggregation/{ => Bucketing}/Missing.md | 0 docs/Aggregation/{ => Bucketing}/Nested.md | 0 docs/Aggregation/{ => Bucketing}/Range.md | 0 .../{ => Bucketing}/ReverseNested.md | 0 .../Aggregation/{ => Bucketing}/SamplerAgg.md | 0 .../{ => Bucketing}/SignificantTerms.md | 0 docs/Aggregation/{ => Bucketing}/Terms.md | 0 docs/Aggregation/Matrix/MatrixStats.md | 0 docs/Aggregation/{ => Metric}/Avg.md | 0 docs/Aggregation/{ => Metric}/Cardinality.md | 0 .../Aggregation/{ => Metric}/ExtendedStats.md | 0 docs/Aggregation/{ => Metric}/GeoBounds.md | 0 docs/Aggregation/{ => Metric}/GeoCentroid.md | 0 docs/Aggregation/{ => Metric}/Max.md | 0 docs/Aggregation/{ => Metric}/Min.md | 0 .../{ => Metric}/PercentileRanks.md | 0 docs/Aggregation/{ => Metric}/Percentiles.md | 0 docs/Aggregation/Metric/ScriptedMetric.md | 0 docs/Aggregation/{ => Metric}/Stats.md | 0 docs/Aggregation/{ => Metric}/Sum.md | 0 docs/Aggregation/{ => Metric}/TopHits.md | 0 docs/Aggregation/{ => Metric}/ValueCount.md | 0 .../Matrix/MatrixStatsAggregation.php | 110 ++++++++++++++++++ src/Search.php | 5 + 37 files changed, 128 insertions(+), 13 deletions(-) rename docs/Aggregation/{ => Bucketing}/Children.md (100%) rename docs/Aggregation/{ => Bucketing}/DateHistogram.md (100%) rename docs/Aggregation/{ => Bucketing}/DateRange.md (100%) create mode 100644 docs/Aggregation/Bucketing/DiversifiedSampler.md rename docs/Aggregation/{ => Bucketing}/Filter.md (100%) rename docs/Aggregation/{ => Bucketing}/Filters.md (100%) rename docs/Aggregation/{ => Bucketing}/GeoDistance.md (100%) rename docs/Aggregation/{ => Bucketing}/GeoHashGrid.md (100%) rename docs/Aggregation/{ => Bucketing}/Global.md (100%) rename docs/Aggregation/{ => Bucketing}/Histogram.md (100%) rename docs/Aggregation/{ => Bucketing}/Ipv4Range.md (100%) rename docs/Aggregation/{ => Bucketing}/Missing.md (100%) rename docs/Aggregation/{ => Bucketing}/Nested.md (100%) rename docs/Aggregation/{ => Bucketing}/Range.md (100%) rename docs/Aggregation/{ => Bucketing}/ReverseNested.md (100%) rename docs/Aggregation/{ => Bucketing}/SamplerAgg.md (100%) rename docs/Aggregation/{ => Bucketing}/SignificantTerms.md (100%) rename docs/Aggregation/{ => Bucketing}/Terms.md (100%) create mode 100644 docs/Aggregation/Matrix/MatrixStats.md rename docs/Aggregation/{ => Metric}/Avg.md (100%) rename docs/Aggregation/{ => Metric}/Cardinality.md (100%) rename docs/Aggregation/{ => Metric}/ExtendedStats.md (100%) rename docs/Aggregation/{ => Metric}/GeoBounds.md (100%) rename docs/Aggregation/{ => Metric}/GeoCentroid.md (100%) rename docs/Aggregation/{ => Metric}/Max.md (100%) rename docs/Aggregation/{ => Metric}/Min.md (100%) rename docs/Aggregation/{ => Metric}/PercentileRanks.md (100%) rename docs/Aggregation/{ => Metric}/Percentiles.md (100%) create mode 100644 docs/Aggregation/Metric/ScriptedMetric.md rename docs/Aggregation/{ => Metric}/Stats.md (100%) rename docs/Aggregation/{ => Metric}/Sum.md (100%) rename docs/Aggregation/{ => Metric}/TopHits.md (100%) rename docs/Aggregation/{ => Metric}/ValueCount.md (100%) create mode 100644 src/Aggregation/Matrix/MatrixStatsAggregation.php diff --git a/README.md b/README.md index 553756a..ad05046 100644 --- a/README.md +++ b/README.md @@ -15,15 +15,15 @@ is the preffered and recommended way to ask ONGR support questions. | Elasticsearch version | ElasticsearchDSL version | | --------------------- | --------------------------- | -| >= 5.0 | >= 5.0 | -| >= 2.0, < 5.0 | >= 2.0, < 5.0 | +| >= 6.0 | >= 6.0 | +| >= 5.0, < 6.0 | >= 5.0 | +| >= 2.0, < 5.0 | >= 2.0 | | >= 1.0, < 2.0 | 1.x | -| <= 0.90.x | 0.x | +| <= 0.90.x | not supported | ## Documentation -The latest library online documentation of the bundle [is here](http://docs.ongr.io/ElasticsearchDSL). If you need 2.x -docs you can find it in [the github branch here](https://github.com/ongr-io/ElasticsearchDSL/tree/2.x/docs). +[The online documentation of the bundle is here](docs/index.md) ## Try it! @@ -44,7 +44,7 @@ Elasticsearch DSL was extracted from [Elasticsearch Bundle](https://github.com/o If you dont want to use Symfony or Elasticsearch bundle, no worries, you can use it in any project together with [elasticsearch-php](https://github.com/elastic/elasticsearch-php). Here's the example: If you are using Symfony there is also the [ElasticsearchBundle](https://github.com/ongr-io/ElasticsearchBundle) -which provides full integration with Elasticsearch DSL. +which provides full integration with Elasticsearch DSL. The library is standalone and is not coupled with any framework. You can use it in any PHP project, the only requirement is composer. Here's the example: @@ -54,7 +54,7 @@ Create search: ```php <?php require 'vendor/autoload.php'; //Composer autoload - + $client = ClientBuilder::create()->build(); //elasticsearch-php client $matchAll = new ONGR\ElasticsearchDSL\Query\MatchAllQuery(); diff --git a/composer.json b/composer.json index f8eeb5b..c9db5e9 100644 --- a/composer.json +++ b/composer.json @@ -11,14 +11,14 @@ } ], "require": { - "php": ">=5.6", - "symfony/serializer": "~2.7|~3.0", + "php": ">=7.0", + "symfony/serializer": "~3.0|~4.0", "paragonie/random_compat": "^2.0", - "elasticsearch/elasticsearch": "~5.0" + "elasticsearch/elasticsearch": "~6.0" }, "require-dev": { - "phpunit/phpunit": "~5.6", - "squizlabs/php_codesniffer": "~2.0", + "phpunit/phpunit": "~6.0", + "squizlabs/php_codesniffer": "~3.0", "satooshi/php-coveralls": "~1.0" }, "autoload": { @@ -34,7 +34,7 @@ "minimum-stability": "dev", "extra": { "branch-alias": { - "dev-master": "5.1-dev" + "dev-master": "6.1-dev" } } } diff --git a/docs/Aggregation/Children.md b/docs/Aggregation/Bucketing/Children.md similarity index 100% rename from docs/Aggregation/Children.md rename to docs/Aggregation/Bucketing/Children.md diff --git a/docs/Aggregation/DateHistogram.md b/docs/Aggregation/Bucketing/DateHistogram.md similarity index 100% rename from docs/Aggregation/DateHistogram.md rename to docs/Aggregation/Bucketing/DateHistogram.md diff --git a/docs/Aggregation/DateRange.md b/docs/Aggregation/Bucketing/DateRange.md similarity index 100% rename from docs/Aggregation/DateRange.md rename to docs/Aggregation/Bucketing/DateRange.md diff --git a/docs/Aggregation/Bucketing/DiversifiedSampler.md b/docs/Aggregation/Bucketing/DiversifiedSampler.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/Aggregation/Filter.md b/docs/Aggregation/Bucketing/Filter.md similarity index 100% rename from docs/Aggregation/Filter.md rename to docs/Aggregation/Bucketing/Filter.md diff --git a/docs/Aggregation/Filters.md b/docs/Aggregation/Bucketing/Filters.md similarity index 100% rename from docs/Aggregation/Filters.md rename to docs/Aggregation/Bucketing/Filters.md diff --git a/docs/Aggregation/GeoDistance.md b/docs/Aggregation/Bucketing/GeoDistance.md similarity index 100% rename from docs/Aggregation/GeoDistance.md rename to docs/Aggregation/Bucketing/GeoDistance.md diff --git a/docs/Aggregation/GeoHashGrid.md b/docs/Aggregation/Bucketing/GeoHashGrid.md similarity index 100% rename from docs/Aggregation/GeoHashGrid.md rename to docs/Aggregation/Bucketing/GeoHashGrid.md diff --git a/docs/Aggregation/Global.md b/docs/Aggregation/Bucketing/Global.md similarity index 100% rename from docs/Aggregation/Global.md rename to docs/Aggregation/Bucketing/Global.md diff --git a/docs/Aggregation/Histogram.md b/docs/Aggregation/Bucketing/Histogram.md similarity index 100% rename from docs/Aggregation/Histogram.md rename to docs/Aggregation/Bucketing/Histogram.md diff --git a/docs/Aggregation/Ipv4Range.md b/docs/Aggregation/Bucketing/Ipv4Range.md similarity index 100% rename from docs/Aggregation/Ipv4Range.md rename to docs/Aggregation/Bucketing/Ipv4Range.md diff --git a/docs/Aggregation/Missing.md b/docs/Aggregation/Bucketing/Missing.md similarity index 100% rename from docs/Aggregation/Missing.md rename to docs/Aggregation/Bucketing/Missing.md diff --git a/docs/Aggregation/Nested.md b/docs/Aggregation/Bucketing/Nested.md similarity index 100% rename from docs/Aggregation/Nested.md rename to docs/Aggregation/Bucketing/Nested.md diff --git a/docs/Aggregation/Range.md b/docs/Aggregation/Bucketing/Range.md similarity index 100% rename from docs/Aggregation/Range.md rename to docs/Aggregation/Bucketing/Range.md diff --git a/docs/Aggregation/ReverseNested.md b/docs/Aggregation/Bucketing/ReverseNested.md similarity index 100% rename from docs/Aggregation/ReverseNested.md rename to docs/Aggregation/Bucketing/ReverseNested.md diff --git a/docs/Aggregation/SamplerAgg.md b/docs/Aggregation/Bucketing/SamplerAgg.md similarity index 100% rename from docs/Aggregation/SamplerAgg.md rename to docs/Aggregation/Bucketing/SamplerAgg.md diff --git a/docs/Aggregation/SignificantTerms.md b/docs/Aggregation/Bucketing/SignificantTerms.md similarity index 100% rename from docs/Aggregation/SignificantTerms.md rename to docs/Aggregation/Bucketing/SignificantTerms.md diff --git a/docs/Aggregation/Terms.md b/docs/Aggregation/Bucketing/Terms.md similarity index 100% rename from docs/Aggregation/Terms.md rename to docs/Aggregation/Bucketing/Terms.md diff --git a/docs/Aggregation/Matrix/MatrixStats.md b/docs/Aggregation/Matrix/MatrixStats.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/Aggregation/Avg.md b/docs/Aggregation/Metric/Avg.md similarity index 100% rename from docs/Aggregation/Avg.md rename to docs/Aggregation/Metric/Avg.md diff --git a/docs/Aggregation/Cardinality.md b/docs/Aggregation/Metric/Cardinality.md similarity index 100% rename from docs/Aggregation/Cardinality.md rename to docs/Aggregation/Metric/Cardinality.md diff --git a/docs/Aggregation/ExtendedStats.md b/docs/Aggregation/Metric/ExtendedStats.md similarity index 100% rename from docs/Aggregation/ExtendedStats.md rename to docs/Aggregation/Metric/ExtendedStats.md diff --git a/docs/Aggregation/GeoBounds.md b/docs/Aggregation/Metric/GeoBounds.md similarity index 100% rename from docs/Aggregation/GeoBounds.md rename to docs/Aggregation/Metric/GeoBounds.md diff --git a/docs/Aggregation/GeoCentroid.md b/docs/Aggregation/Metric/GeoCentroid.md similarity index 100% rename from docs/Aggregation/GeoCentroid.md rename to docs/Aggregation/Metric/GeoCentroid.md diff --git a/docs/Aggregation/Max.md b/docs/Aggregation/Metric/Max.md similarity index 100% rename from docs/Aggregation/Max.md rename to docs/Aggregation/Metric/Max.md diff --git a/docs/Aggregation/Min.md b/docs/Aggregation/Metric/Min.md similarity index 100% rename from docs/Aggregation/Min.md rename to docs/Aggregation/Metric/Min.md diff --git a/docs/Aggregation/PercentileRanks.md b/docs/Aggregation/Metric/PercentileRanks.md similarity index 100% rename from docs/Aggregation/PercentileRanks.md rename to docs/Aggregation/Metric/PercentileRanks.md diff --git a/docs/Aggregation/Percentiles.md b/docs/Aggregation/Metric/Percentiles.md similarity index 100% rename from docs/Aggregation/Percentiles.md rename to docs/Aggregation/Metric/Percentiles.md diff --git a/docs/Aggregation/Metric/ScriptedMetric.md b/docs/Aggregation/Metric/ScriptedMetric.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/Aggregation/Stats.md b/docs/Aggregation/Metric/Stats.md similarity index 100% rename from docs/Aggregation/Stats.md rename to docs/Aggregation/Metric/Stats.md diff --git a/docs/Aggregation/Sum.md b/docs/Aggregation/Metric/Sum.md similarity index 100% rename from docs/Aggregation/Sum.md rename to docs/Aggregation/Metric/Sum.md diff --git a/docs/Aggregation/TopHits.md b/docs/Aggregation/Metric/TopHits.md similarity index 100% rename from docs/Aggregation/TopHits.md rename to docs/Aggregation/Metric/TopHits.md diff --git a/docs/Aggregation/ValueCount.md b/docs/Aggregation/Metric/ValueCount.md similarity index 100% rename from docs/Aggregation/ValueCount.md rename to docs/Aggregation/Metric/ValueCount.md diff --git a/src/Aggregation/Matrix/MatrixStatsAggregation.php b/src/Aggregation/Matrix/MatrixStatsAggregation.php new file mode 100644 index 0000000..7e8d96c --- /dev/null +++ b/src/Aggregation/Matrix/MatrixStatsAggregation.php @@ -0,0 +1,110 @@ +<?php + +/* + * This file is part of the ONGR package. + * + * (c) NFQ Technologies UAB <info@nfq.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchDSL\Aggregation\Matrix; +use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation; +use ONGR\ElasticsearchDSL\Aggregation\Type\MetricTrait; + +/** + * Class representing Max Aggregation. + * + * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html + */ +class MaxAggregation extends AbstractAggregation +{ + use MetricTrait; + + /** + * @var string Used for multi value aggregation fields to pick a value. + */ + private $mode; + + /** + * @var array Defines how documents that are missing a value should be treated. + */ + private $missing; + + /** + * Inner aggregations container init. + * + * @param string $name + * @param string|array $field Fields list to aggregate. + * @param array $missing + * @param string $mode + */ + public function __construct($name, $field, $missing = null, $mode = null) + { + parent::__construct($name); + + $this->setField($field); + $this->setMode($mode); + $this->missing = $missing; + } + + /** + * @return string + */ + public function getMode() + { + return $this->mode; + } + + /** + * @param string $mode + */ + public function setMode($mode) + { + $this->mode = $mode; + } + + /** + * @return array + */ + public function getMissing() + { + return $this->missing; + } + + /** + * @param array $missing + */ + public function setMissing($missing) + { + $this->missing = $missing; + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'matrix_stats'; + } + + protected function getArray() + { + $out = []; + if ($this->getField()) { + $out['fields'] = $this->getField(); + } + + if($this->getMode()) { + $out['mode'] = $this->getMode(); + } + + + if($this->getMissing()) { + $out['missing'] = $this->getMissing(); + } + + return $out; + } +} diff --git a/src/Search.php b/src/Search.php index 22dbc83..5f84bba 100644 --- a/src/Search.php +++ b/src/Search.php @@ -672,6 +672,11 @@ class Search 'size', 'search_type', 'scroll', + 'allow_no_indices', + 'ignore_unavailable', + 'typed_keys', + 'pre_filter_shard_size', + 'ignore_unavailable', ])) { $this->uriParams[$name] = $value; } else { -- GitLab