diff --git a/docs/Aggregation/Avg.md b/docs/Aggregation/Avg.md index c72b519d98fb1da42cf1b9d9cb103e7966cd10c3..1a9e2212598f1c1dacfbc8be424f408acc73956e 100644 --- a/docs/Aggregation/Avg.md +++ b/docs/Aggregation/Avg.md @@ -10,7 +10,7 @@ A single-value metrics aggregation that computes the average of numeric values t ```JSON { "aggregations": { - "agg_avg_grade": { + "avg_grade": { "avg": { "field": "grade" } @@ -31,4 +31,4 @@ $search->addAggregation($avgAggregation); $queryArray = $search->toArray(); ``` -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html \ No newline at end of file +[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html diff --git a/docs/Aggregation/Cardinality.md b/docs/Aggregation/Cardinality.md index 642869f4097376fbc11ea09e85d6c5802f326b94..e129aa668516daf7d15e077e58f343455b8d2385 100644 --- a/docs/Aggregation/Cardinality.md +++ b/docs/Aggregation/Cardinality.md @@ -9,7 +9,7 @@ A single-value metrics aggregation that calculates an approximate count of disti ```JSON { "aggregations" : { - "agg_author_count" : { + "author_count" : { "cardinality" : { "field" : "author" } @@ -21,7 +21,8 @@ A single-value metrics aggregation that calculates an approximate count of disti And now the query via DSL: ```php -$cardinalityAggregation = new CardinalityAggregation('author_count', 'author'); +$cardinalityAggregation = new CardinalityAggregation('author_count'); +$cardinalityAggregation->setField('author'); $search = new Search(); $search->addAggregation($cardinalityAggregation); diff --git a/docs/Aggregation/Children.md b/docs/Aggregation/Children.md index 4358561d4ca8569a78e081c4bd0ce9e127ca8513..11a14a1ef998aef9b33cd50b81ca1e3072e60f43 100644 --- a/docs/Aggregation/Children.md +++ b/docs/Aggregation/Children.md @@ -10,12 +10,12 @@ document types to buckets on child documents. ```JSON { "aggregations": { - "agg_author_count": { + "author_count": { "children": { "type": "answer" }, "aggregations": { - "agg_top_names": { + "top_names": { "terms": { "field": "owner.display_name" } diff --git a/docs/Aggregation/DateRange.md b/docs/Aggregation/DateRange.md index c1f48a0e37af4b9b4bb12497e1836f80a57ffb1a..6723c6c0757f77d8717af73be6b02fdc3e44e60f 100644 --- a/docs/Aggregation/DateRange.md +++ b/docs/Aggregation/DateRange.md @@ -9,13 +9,13 @@ A range aggregation that is dedicated for date values. ```JSON { "aggregations": { - "agg_range": { + "range": { "date_range": { "field": "date", "format": "MM-yyy", "ranges": [ - { "to": "now-10M/M" }, - { "from": "now-10M/M" } + { "to": "now-10M/M" }, + { "from": "now-10M/M" } ] } } @@ -31,9 +31,14 @@ $dateRangeAggregation->setField('date'); $dateRangeAggregation->setFormat('MM-yyy'); $dateRangeAggregation->addRange(null, 'now-10M/M'); $dateRangeAggregation->addRange('now-10M/M', null); + +$search = new Search(); +$search->addAggregation($dateRangeAggregation); + +$queryArray = $search->toArray(); ``` -Or : +Or : ```php $dateRangeAggregation = new DateRangeAggregation( @@ -48,6 +53,8 @@ $dateRangeAggregation = new DateRangeAggregation( $search = new Search(); $search->addAggregation($dateRangeAggregation); + +$queryArray = $search->toArray(); ``` [1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html diff --git a/docs/Aggregation/ExtendedStats.md b/docs/Aggregation/ExtendedStats.md index 69225844bc342d5048d83690e1bf960dfbcad355..189855b0f6602429ef44b4cacfc08de3ddae8219 100644 --- a/docs/Aggregation/ExtendedStats.md +++ b/docs/Aggregation/ExtendedStats.md @@ -9,7 +9,7 @@ A multi-value metrics aggregation that computes stats over numeric values extrac ```JSON { "aggregations" : { - "agg_grades_stats" : { + "grades_stats" : { "extended_stats" : { "field" : "grade" } } } diff --git a/docs/Aggregation/Filter.md b/docs/Aggregation/Filter.md index 9a7a4d21b62f37a1aefa1f3f62817d5dc0fd245f..96a2dbb86ee48fd1d027221c8268d7e3d6e0082a 100644 --- a/docs/Aggregation/Filter.md +++ b/docs/Aggregation/Filter.md @@ -11,10 +11,10 @@ context to a specific set of documents. ```JSON { "aggregations" : { - "agg_red_products" : { + "grades_stats" : { "filter" : { "term": { "color": "red" } }, - "aggs" : { - "agg_avg_price" : { "avg" : { "field" : "price" } } + "aggregations" : { + "avg_price" : { "avg" : { "field" : "price" } } } } } diff --git a/docs/Aggregation/Filters.md b/docs/Aggregation/Filters.md index 8ec4451144eccebeaf46f0748e4aa6dad10c14a1..b36fecc13f3c44bf669d30bf608d15b4b2e534f5 100644 --- a/docs/Aggregation/Filters.md +++ b/docs/Aggregation/Filters.md @@ -14,15 +14,15 @@ in exception. ```JSON { "aggregations" : { - "agg_messages" : { + "grades_stats" : { "filters" : { "filters" : { - "errors" : { "term" : { "body" : "error" }}, - "warnings" : { "term" : { "body" : "warning" }} + "error" : { "term" : { "body" : "error" }}, + "warning" : { "term" : { "body" : "warning" }} } }, "aggregations" : { - "agg_monthly" : { + "monthly" : { "histogram" : { "field" : "timestamp", "interval" : "1M" @@ -60,6 +60,31 @@ $queryArray = $search->toArray(); ## Anonymous example +```JSON +{ + "aggregations" : { + "grades_stats" : { + "filters" : { + "filters" : [ + { "term" : { "body" : "error" }}, + { "term" : { "body" : "warning" }} + ] + } + }, + "aggregations" : { + "monthly" : { + "histogram" : { + "field" : "timestamp", + "interval" : "1M" + } + } + } + } + } +} +``` +And now the query via DSL: + ```php $errorTermFilter = new TermFilter('body', 'error'); $warningTermFilter = new TermFilter('body', 'warning'); @@ -83,4 +108,4 @@ $search->addAggregation($filterAggregation); $queryArray = $search->toArray(); ``` -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html \ No newline at end of file +[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html diff --git a/docs/Aggregation/GeoBounds.md b/docs/Aggregation/GeoBounds.md index 0e75e1056a9005d90e683814e47901f44a5265b5..2b0d8a554dc505ad030504555efeb6f0d7ca3d61 100644 --- a/docs/Aggregation/GeoBounds.md +++ b/docs/Aggregation/GeoBounds.md @@ -9,7 +9,7 @@ A metric aggregation that computes the bounding box containing all geo_point val ```JSON { "aggregations" : { - "agg_viewport" : { + "viewport" : { "geo_bounds" : { "field" : "location", "wrap_longitude" : true diff --git a/docs/Aggregation/GeoHashGrid.md b/docs/Aggregation/GeoHashGrid.md index e372264601bfe2ebb7243a4fb3117fb574ab0a63..ac9b5ba37627f154cb1dbc73f365f67e3792245e 100644 --- a/docs/Aggregation/GeoHashGrid.md +++ b/docs/Aggregation/GeoHashGrid.md @@ -10,7 +10,7 @@ that represent cells in a grid. ```JSON { "aggregations" : { - "agg_GrainGeoHashGrid" : { + "GrainGeoHashGrid" : { "geohash_grid" : { "field" : "location", "precision" : 3 diff --git a/docs/Aggregation/Global.md b/docs/Aggregation/Global.md index fcb7821cfe92afac4ceec8e8844053321109b17f..d950f92855904a1abcae30a43d77df3d0d4fea98 100644 --- a/docs/Aggregation/Global.md +++ b/docs/Aggregation/Global.md @@ -11,10 +11,10 @@ you’re searching on, but is **not influenced** by the search query itself. ```JSON { "aggregations": { - "agg_all_products": { + "all_products": { "global": {}, "aggregations": { - "agg_avg_price": { + "avg_price": { "avg": { "field": "price" } diff --git a/docs/Aggregation/Histogram.md b/docs/Aggregation/Histogram.md index be18516a4f0ae96ca0245180c2989d9fc79d8104..b4e67fd6edc3abf00467447fcebe08c2f60c013c 100644 --- a/docs/Aggregation/Histogram.md +++ b/docs/Aggregation/Histogram.md @@ -10,7 +10,7 @@ the documents. It dynamically builds fixed size (a.k.a. interval) buckets over t ```JSON { "aggregations": { - "agg_prices": { + "prices": { "histogram": { "field": "price", "interval": 50 diff --git a/docs/Aggregation/Ipv4Range.md b/docs/Aggregation/Ipv4Range.md index 215d91c7e5189e1d9cfbd0b942ba2c7ded4e9e0b..4a629a617bc227c2f565cabea7de25197ca2de58 100644 --- a/docs/Aggregation/Ipv4Range.md +++ b/docs/Aggregation/Ipv4Range.md @@ -10,7 +10,7 @@ range aggregation for IPv4 typed fields. ```JSON { "aggregations" : { - "agg_ip_range" : { + "ip_range" : { "ip_range" : { "field" : "ip", "ranges" : [ diff --git a/docs/Aggregation/Missing.md b/docs/Aggregation/Missing.md index 1f3cdd302ef601c272588f075a092d9eb6c8b2e1..0485569ab8ade148cc5f3fc49bfdde8b1f041e81 100644 --- a/docs/Aggregation/Missing.md +++ b/docs/Aggregation/Missing.md @@ -10,7 +10,7 @@ in the current document set context that are missing a field value. ```JSON { "aggregations" : { - "agg_products_without_a_price" : { + "products_without_a_price" : { "missing" : { "field" : "price" } } } diff --git a/docs/Aggregation/Nested.md b/docs/Aggregation/Nested.md index f7cf99c25f922eca4dd58a4ba47c9f3f3f2aec1e..29b20d1e52eea1c71a4ace6c48b729b2ea96d41b 100644 --- a/docs/Aggregation/Nested.md +++ b/docs/Aggregation/Nested.md @@ -9,12 +9,12 @@ A special single bucket aggregation that enables aggregating nested documents. ```JSON { "aggregations" : { - "agg_resellers" : { + "resellers" : { "nested" : { "path" : "resellers" }, "aggregations" : { - "agg_min_price" : { "min" : { "field" : "resellers.price" } } + "min_price" : { "min" : { "field" : "resellers.price" } } } } } diff --git a/docs/Aggregation/PercentileRanks.md b/docs/Aggregation/PercentileRanks.md index 52f3826f01418646a43a77a60edc06113c499feb..dbd8c1f0e39d71b917fbfd72d2285b1ee25d1699 100644 --- a/docs/Aggregation/PercentileRanks.md +++ b/docs/Aggregation/PercentileRanks.md @@ -10,7 +10,7 @@ ranks over numeric values extracted from the aggregated documents. ```JSON { "aggregations" : { - "agg_load_time_outlier" : { + "load_time_outlier" : { "percentile_ranks" : { "field" : "load_time", "values" : [15, 30] diff --git a/docs/Aggregation/Percentiles.md b/docs/Aggregation/Percentiles.md index c4c4481c8607e8528f30f103416d4900a85e2dac..7093d9c28ada0e4ff265954362a0953c26d4f269 100644 --- a/docs/Aggregation/Percentiles.md +++ b/docs/Aggregation/Percentiles.md @@ -10,7 +10,7 @@ numeric values extracted from the aggregated documents. ```JSON { "aggregations" : { - "agg_load_time_outlier" : { + "load_time_outlier" : { "percentiles" : { "field" : "load_time" } diff --git a/docs/Aggregation/Range.md b/docs/Aggregation/Range.md index 45b9facf572ee2aa7784db345b41d94e85ece156..d43e19b015858bb955187ce02f9ff3c20ece53d7 100644 --- a/docs/Aggregation/Range.md +++ b/docs/Aggregation/Range.md @@ -10,9 +10,10 @@ ranges - each representing a bucket. ```JSON { "aggs" : { - "agg_price_ranges" : { + "price_ranges" : { "range" : { "field" : "price", + "keyed" : false, "ranges" : [ { "to" : 50 }, { "from" : 50, "to" : 100 }, diff --git a/docs/Aggregation/ReverseNested.md b/docs/Aggregation/ReverseNested.md index 7ef138aa86cc3cec6e422d1482d3b6e679af819a..d375bb9ede3148ecc2632fb29c71b3b324b60013 100644 --- a/docs/Aggregation/ReverseNested.md +++ b/docs/Aggregation/ReverseNested.md @@ -9,17 +9,17 @@ A special single bucket aggregation that enables aggregating on parent docs from ```JSON { "aggregations": { - "agg_comments": { + "comments": { "nested": { "path": "comments" }, "aggregations": { - "agg_top_usernames": { + "top_usernames": { "terms": { "field": "comments.username" }, "aggregations": { - "agg_comment_to_issue": { + "comment_to_issue": { "reverse_nested": {}, "aggregations": { "top_tags_per_comment": { diff --git a/docs/Aggregation/Stats.md b/docs/Aggregation/Stats.md index e4ca438410eb103fef5dcdf473112b2c7b1a7dbe..1871f9e16dd508873cd98b497a17ed990357a9c3 100644 --- a/docs/Aggregation/Stats.md +++ b/docs/Aggregation/Stats.md @@ -10,7 +10,7 @@ values extracted from the aggregated documents. ```JSON { "aggregations" : { - "agg_grades_stats" : { "stats" : { "field" : "grade" } } + "grades_stats" : { "stats" : { "field" : "grade" } } } } ``` diff --git a/docs/Aggregation/Sum.md b/docs/Aggregation/Sum.md index bc5929ac093dfd2f287d0d1f7e34f84a641f335a..a11be599719fd1ee0126bae00d40ead6f2baa31d 100644 --- a/docs/Aggregation/Sum.md +++ b/docs/Aggregation/Sum.md @@ -9,7 +9,7 @@ A single-value metrics aggregation that sums up numeric values that are extracte ```JSON { "aggregations" : { - "agg_intraday_return" : { "sum" : { "field" : "change" } } + "intraday_return" : { "sum" : { "field" : "change" } } } } ``` diff --git a/docs/Aggregation/Terms.md b/docs/Aggregation/Terms.md index 66a8213c01d838b6b787d7850f99a9099bd5b4e6..9e5c8dbc5d3651ed520ffbd38cae9f3524be3bec 100644 --- a/docs/Aggregation/Terms.md +++ b/docs/Aggregation/Terms.md @@ -10,7 +10,7 @@ built - one per unique value. ```JSON { "aggregations" : { - "agg_genders" : { + "genders" : { "terms" : { "field" : "gender" } } } diff --git a/docs/Aggregation/TopHits.md b/docs/Aggregation/TopHits.md index 33ba81ea357109dd0d271f4ad8de6d06c70973e7..f70995be58711964ae1b7aa3841626f962e686f1 100644 --- a/docs/Aggregation/TopHits.md +++ b/docs/Aggregation/TopHits.md @@ -16,7 +16,7 @@ so that the top matching documents can be aggregated per bucket. "field": "tags", "size": 3 }, - "aggs": { + "aggregations": { "top_tag_hits": { "top_hits": { "sort": [ diff --git a/docs/Aggregation/ValueCount.md b/docs/Aggregation/ValueCount.md index 359403ed207a449d03bd976f3ba83798b5c5b831..fb004397c5e5a79f75c235c21de1cc7208fff805 100644 --- a/docs/Aggregation/ValueCount.md +++ b/docs/Aggregation/ValueCount.md @@ -8,7 +8,7 @@ A single-value metrics aggregation that counts the number of values that are ext ```JSON { - "aggs" : { + "aggregations" : { "grades_count" : { "value_count" : { "field" : "grade" } } } } diff --git a/docs/Query/Bool.md b/docs/Query/Bool.md index f3182435275f3c29519920b2f896253bc41910e2..babd6e67b3476e26ea91df20d41a4e8f260e1936 100644 --- a/docs/Query/Bool.md +++ b/docs/Query/Bool.md @@ -41,12 +41,16 @@ $termQueryForTag1 = new TermQuery("tag", "wow"); $termQueryForTag2 = new TermQuery("tag", "elasticsearch"); $rangeQuery = new RangeQuery("age", ["from" => 10, "to" => 20]); +$bool = new BoolQuery(); +$bool->addParameter("minimum_should_match", 1); +$bool->addParameter("boost", 1); +$bool->add($termQueryForUser, BoolQuery::MUST); +$bool->add($rangeQuery, BoolQuery::MUST_NOT); +$bool->add($termQueryForTag1, BoolQuery::SHOULD); +$bool->add($termQueryForTag2, BoolQuery::SHOULD); + $search = new Search(); -$search->addQuery($termQueryForUser, BoolQuery::MUST); -$search->addQuery($rangeQuery, BoolQuery::MUST_NOT); -$search->addQuery($termQueryForTag1, BoolQuery::SHOULD); -$search->addQuery($termQueryForTag2, BoolQuery::SHOULD); -$search->setBoolQueryParameters(["minimum_should_match" => 1, "boost" => 1]); +$search->addQuery($bool); $queryArray = $search->toArray(); ``` diff --git a/docs/Query/Wildcard.md b/docs/Query/Wildcard.md index 4c646c5e9ff31628befcf5bb5cd1cd3baec36e93..e73500b8707e46e4a6c1785b29d6432f9114f3bc 100644 --- a/docs/Query/Wildcard.md +++ b/docs/Query/Wildcard.md @@ -1 +1,32 @@ -# Wildcard Query \ No newline at end of file +# Wildcard query + +> More info about Wildcard query is in the [official elasticsearch docs][1] + +Matches documents that have fields matching a wildcard expression (not analyzed). + +Lets take an example to write a wildcard query with Elasticsearch DSL. + +```JSON +{ + "wildcard" : { + "user" : { + "value" : "ki*y" + }, + "boost" : 2.0 + } +} +``` + +And now the query via DSL: + +```php + +$search = new Search(); +$wildcard= new WildcardQuery('user', 'ki*y', ["boost" => 2.0]); +$search->addQuery($wildcard); +$queryArray = $search->toArray(); + +``` + + +[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html