diff --git a/CHANGELOG.md b/CHANGELOG.md index eba6f0acc6a2fde88f60e098e6318e245d467b7e..497a4d5c384ec5b8180918f19e56b8262d4f2187 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,14 @@ # CHANGELOG v5.0.0 (2017-x) --- -- **[BC break]** Removed deprecated aggregation classes. -- **[BC break]** Removed deprecated query classes. -- **[BC break]** `Search::getQueryParams()` changed to `Search::getUriParams()`. -- **[BC break]** `FilterEndpoint` was removed due deprecated filters. +- **Namespace for some queries were changed**. Queries were consolidated to a domain like Elasticsearch does. All queries were grouped to `Compound`, `FullText`, `Geo`, `Joining`, `Span`, `Specialized` and `TermLevel`. +- PHP version support changed to >=5.6 +- Added `elasticsearch\elasticsearch` to required dependency list in the composer.json. +- Deprecated aggregations removed. Check if the namespace is correct. All aggregations grouped to `Bucketing`, `Metric` and `Pipeline` namespaces. +- `Search::getQueryParams()` changed to `Search::getUriParams()`. All setter's for request URI parameters removed in favor of `uriParams` container. You can add URI parameters by `addUriParam`, and this function also has validation. +- `Search::setFields()` and `Search::getFields()` were changed to `Search::setStoredFields()` and `Search::getStoredFields()`. +- `FilterEndpoint` was removed due to deprecated filters in elasticsearch. +- Added missing scroll param to URL params (#202) v2.2.1 (2017-01-26) --- diff --git a/README.md b/README.md index a1e2c9ccdb07b8a133d06b5ffd5181846b9c8e37..553756ab8ae83169d3b79b0d0a02df0a5a4367b2 100644 --- a/README.md +++ b/README.md @@ -15,14 +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 | >= 5.0 | +| >= 2.0, < 5.0 | >= 2.0, < 5.0 | | >= 1.0, < 2.0 | 1.x | -| <= 0.90.x | not supported | +| <= 0.90.x | 0.x | ## Documentation -[The online documentation of the bundle is here](docs/index.md) +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). ## Try it! @@ -34,24 +35,27 @@ Install library with [composer](https://getcomposer.org): $ composer require ongr/elasticsearch-dsl ``` +> [elasticsearch-php](https://github.com/elastic/elasticsearch-php) client is defined in the composer requirements, no need to install it. + ### Search Elasticsearch DSL was extracted from [Elasticsearch Bundle](https://github.com/ongr-io/ElasticsearchBundle) to provide standalone query dsl for [elasticsearch-php](https://github.com/elastic/elasticsearch-php). Examples how to use it together with [Elasticsearch Bundle](https://github.com/ongr-io/ElasticsearchBundle) can be found in the [Elasticsearch Bundle docs](https://github.com/ongr-io/ElasticsearchBundle/blob/master/Resources/doc/search.md). 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: -Install `elasticsearch-php`: +If you are using Symfony there is also the [ElasticsearchBundle](https://github.com/ongr-io/ElasticsearchBundle) +which provides full integration with Elasticsearch DSL. -```bash -$ composer require elasticsearch/elasticsearch -``` +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: Create search: ```php <?php - require 'vendor/autoload.php'; - $client = ClientBuilder::create()->build(); + require 'vendor/autoload.php'; //Composer autoload + + $client = ClientBuilder::create()->build(); //elasticsearch-php client $matchAll = new ONGR\ElasticsearchDSL\Query\MatchAllQuery(); diff --git a/docs/HowTo/HowToSearch.md b/docs/HowTo/HowToSearch.md index 3541c2b89c117da9e7dacc4bab7b34c260f27d38..25b6b8748b2e8ed129af90304e9dc8e31c8554c2 100644 --- a/docs/HowTo/HowToSearch.md +++ b/docs/HowTo/HowToSearch.md @@ -10,7 +10,7 @@ $search = new Search(); > We won't include namespaces in any examples. Don't worry all class's names are unique, so any IDE editor should autocomplete and include it for you ;). -So, when we have a `Search` object we can start add something to it. Usually you will add `Query`, `Filter` and `Aggregation`. +So, when we have a `Search` object we can start adding something to it. Usually you will add `Query` and `Aggregation`. > More info how create [queries](../Query/index.md) and [aggregations](../Aggregation/index.md) objects. @@ -43,32 +43,40 @@ At the end it will form this query: ### Form a Filter -Since Elasticsearch 2.0 all filters were replaced by queries. Queries acts like -filters when you use them in filter context. - -To add a filter is the same way like a query. First, lets create some `Filter` object. - +Since Elasticsearch 5.0 the support for top level filters was dropped. The same functionality +is now supported via `BoolQuery`. Adding a filter to the bool query is done like so: + ```php -$matchAllQuery = new MatchAllQuery(); -``` - -And simply add to the `Search`: +$search = new Search(); +$boolQuery = new BoolQuery(); +$boolQuery->add(new MatchAllQuery()); +$geoQuery = new TermQuery('field', 'value'); +$boolQuery->add($geoQuery, BoolQuery::FILTER); +$search->addQuery($boolQuery); -```php -$search->addFilter($matchAllQuery); +$search->toArray(); ``` -Unlike `Query`, when we add a `Filter` with our DSL library it will add a query and all necessary stuff for you. So when we add one filter we will get this query: +This will result in -```JSON +``` { - "query": { - "bool": { - "filter": { - "match_all": {} - } - } - } + "query": { + "bool": { + "must": [ + { + "match_all": {} + } + ], + "filter": [ + { + "term": { + "field": "value" + } + } + ] + } + } } ``` @@ -113,63 +121,17 @@ The query will look like: ``` > More info how to form bool queries find in [Bool Query](../Query/Bool.md) chapter. -The same way it works with a `Filter`. Take a look at this example: - -```php -$search = new Search(); -$termFilter = new TermQuery('name', 'ongr'); -$missingFilter = new MissingQuery('disabled'); -$existsFilter = new ExistsQuery('tag'); -$search->addFilter($termFilter); -$search->addFilter($missingFilter); -$search->addFilter($existsFilter, BoolQuery::MUST_NOT); -``` - -Elasticsearch DSL will form this query: - -```JSON -{ - "query": { - "bool": { - "filter": { - "bool": { - "must": [ - { - "term": { - "name": "ongr" - } - }, - { - "missing": { - "field": "disabled" - } - } - ], - "must_not": [ - { - "exists": { - "field": "tag" - } - } - ] - } - } - } - } -} -``` - ### Modify queries ### Sent request to the elasticsearch -And finaly we can pass it to `elasticsearch-php` client. To generate an array for the client we call `toArray()` function. +And finally we can pass it to `elasticsearch-php` client. To generate an array for the client we call `toArray()` function. ```php //from elasticsearch/elasticsearch package -$client = new Elasticsearch\Client(); +$client = ClientBuilder::create()->build(); $searchParams = [ 'index' => 'people', @@ -180,4 +142,4 @@ $searchParams = [ $docs = $client->search($searchParams); ``` -> This example is for elasticsearch/elasticsearch ~1.0 version. +> This example is for elasticsearch/elasticsearch ~5.0 version. diff --git a/docs/Query/TermLevel/Regexp.md b/docs/Query/TermLevel/Regexp.md index d698b004f93bb70aa8c60c7860bc8f1f346aa938..f7b7856d63c7a74f793e9a8421bb7b2c893e630b 100644 --- a/docs/Query/TermLevel/Regexp.md +++ b/docs/Query/TermLevel/Regexp.md @@ -8,7 +8,7 @@ The regexp query allows you to use regular expression term queries. ```JSON { - "filter": { + "query": { "regexp":{ "name.first" : "s.*y" }