Skip to content

Releases: pdphilip/laravel-elasticsearch

v2.7.4

14 Nov 21:33

Choose a tag to compare

New Feature

Distinct and GroupBy

This section covers the implementation of distinct() and groupBy() methods in the Elasticsearch Eloquent model. These methods are interchangeable and use term aggregation under the hood.

This tends to be a core use case for Elasticsearch, for example, to get all the unique user_ids of the users who have been logged in the last 30 days:

Basic Usage

  • Distinct:
// Unique user_ids of users logged in the last 30 days
$users = UserLog::where('created_at', '>=', Carbon::now()->subDays(30))->distinct()->get('user_id');
//or:
$users = UserLog::where('created_at', '>=', Carbon::now()->subDays(30))->select('user_id')->distinct()->get();
  • GroupBy:
// Equivalent to the above distinct query
$users = UserLog::where('created_at', '>=', Carbon::now()->subDays(30))->groupBy('user_id')->get();

Working with Collections

  • The results from these queries are returned as collections, allowing use of standard collection methods.
  • Example of loading related user data:
$users = UserLog::where('created_at', '>=', Carbon::now()->subDays(30))->distinct()->get('user_id');
return $users->load('user');

Multiple Fields Aggregation

  • You can pass multiple fields to perform term aggregation.
  • Example:
$users = UserLog::where('created_at', '>=', Carbon::now()->subDays(30))->distinct()->get(['user_id', 'log_title']);
/** returns: 
{
    "user_id": "1",
    "log_title": "LOGGED_IN"
},
{
    "user_id": "2",
    "log_title": "LOGGED_IN"
},
{
    "user_id": "2",
    "log_title": "LOGGED_OUT"
},
 **/

Ordering by Aggregation Count

  • Results can be sorted based on the count of the aggregated field.
  • Example of ordering by the most logged users:
$users = UserLog::where('created_at', '>=', Carbon::now()->subDays(30))->distinct()->orderBy('_count')->get('user_id');
  • Or you can order by the distinct field, example:
$users = UserLog::where('created_at', '>=', Carbon::now()->subDays(30))->distinct()->orderBy('user_id')->get('user_id');

Returning Count with Distinct Results

  • To include the count of distinct values in the results, use distinct(true):
$users = UserLog::where('created_at', '>=', Carbon::now()->subDays(30))->distinct(true)->orderBy('_count')->get(['user_id']);
/** returns: 
{
    "user_id": "5",
    "user_id_count": 65
},
{
    "user_id": "1",
    "user_id_count": 61
},
{
    "user_id": "9",
    "user_id_count": 54
},
 **/

Pagination Support

  • The distinct() and groupBy() methods support pagination.
  • Example:
$users = UserLog::where('log_title', 'LOGGED_IN')->select('user_id')->distinct()->orderBy('_count')->paginate(20);
//or
$users = UserLog::where('log_title', 'LOGGED_IN')->groupBy('user_id')->orderBy('_count')->paginate(20);

Full Changelog: v2.7.3...v2.7.4

v2.10.2

03 Nov 14:04

Choose a tag to compare

Bug fixes:

  • Geo filtering was always returning all fields, fixed
  • Searching across multiple fields was not honoring 'minShouldMatch()', fixed
  • Schema::reIndex() was broken, works now
  • Schema::getIndices() was broken, works now
  • Schema::hasIndex() was broken, works now
  • Schema::getMappings() was broken, works now
  • Schema::getSettings() was broken, works now
  • Index Blueprint for IP addresses $this->ip('field_name') required an extra invalid parameter, fixed
  • $passthru in Eloquent Builder was failing as Laravel 10 now checks it as lowercased (not camel)

Upgrades

  • Dependency upgrade to "elasticsearch/elasticsearch": "8.10" (from "8.9")
  • Connecter update
    • to include table() method required for User Auth
    • Automatic index prefixing required for schema-related functionality
    • Ability to setIndexPrefix() in the connector on the fly
  • Schema methods for create(), modify(), & setAnalyser() now returns the index in question
  • Code clean up in Model, Query builder and IndexInterpreter
  • Updated docs to include re-indexing example

New Feature

  • updateWithoutRefresh($attriubutes) - works the same as saveWithoutRefresh() & createWithoutRefresh()
  • Schema::getIndex('name') - returns the index with the settings and mappings
  • Index prefix can be overridden,
    ex: Schema::overridePrefix(null)->getIndex('my_index') - returns my_index
    ex: Schema::overridePrefix('something_else')->getIndex('my_index') - returns something_else_my_index

Full Changelog: v2.10.1...v2.10.2

v2.9.4

03 Nov 13:59

Choose a tag to compare

Bug fixes:

  • Geo filtering was always returning all fields, fixed
  • Searching across multiple fields was not honoring 'minShouldMatch()', fixed
  • Schema::reIndex() was broken, works now
  • Schema::getIndices() was broken, works now
  • Schema::hasIndex() was broken, works now
  • Schema::getMappings() was broken, works now
  • Schema::getSettings() was broken, works now
  • Index Blueprint for IP addresses $this->ip('field_name') required an extra invalid parameter, fixed

Upgrades

  • Dependency upgrade to "elasticsearch/elasticsearch": "8.10" (from "8.7")
  • Connecter update
    • to include table() method required for User Auth
    • Automatic index prefixing required for schema-related functionality
    • Ability to setIndexPrefix() in the connector on the fly
  • Schema methods for create(), modify(), & setAnalyser() now returns the index in question
  • Code clean up in Model, Query builder and IndexInterpreter
  • Updated docs to include re-indexing example

New Feature

  • updateWithoutRefresh($attriubutes) - works the same as saveWithoutRefresh() & createWithoutRefresh()
  • Schema::getIndex('name') - returns the index with the settings and mappings
  • Index prefix can be overridden,
    ex: Schema::overridePrefix(null)->getIndex('my_index') - returns my_index
    ex: Schema::overridePrefix('something_else')->getIndex('my_index') - returns something_else_my_index

Full Changelog: v2.9.3...v2.9.4

v2.8.3

03 Nov 13:55

Choose a tag to compare

Bug fixes:

  • Geo filtering was always returning all fields, fixed
  • Searching across multiple fields was not honoring 'minShouldMatch()', fixed
  • Schema::reIndex() was broken, works now
  • Schema::getIndices() was broken, works now
  • Schema::hasIndex() was broken, works now
  • Schema::getMappings() was broken, works now
  • Schema::getSettings() was broken, works now
  • Index Blueprint for IP addresses $this->ip('field_name') required an extra invalid parameter, fixed

Upgrades

  • Dependency upgrade to "elasticsearch/elasticsearch": "8.10" (from "8.7")
  • Connecter update
    • to include table() method required for User Auth
    • Automatic index prefixing required for schema-related functionality
    • Ability to setIndexPrefix() in the connector on the fly
  • Schema methods for create(), modify(), & setAnalyser() now returns the index in question
  • Code clean up in Model, Query builder and IndexInterpreter
  • Updated docs to include re-indexing example

New Feature

  • updateWithoutRefresh($attriubutes) - works the same as saveWithoutRefresh() & createWithoutRefresh()
  • Schema::getIndex('name') - returns the index with the settings and mappings
  • Index prefix can be overridden,
    ex: Schema::overridePrefix(null)->getIndex('my_index') - returns my_index
    ex: Schema::overridePrefix('something_else')->getIndex('my_index') - returns something_else_my_index

Full Changelog: v2.8.2...v2.8.3

v2.7.3

03 Nov 13:44

Choose a tag to compare

Bug fixes:

  • Geo filtering was always returning all fields, fixed
  • Searching across multiple fields was not honoring 'minShouldMatch()', fixed
  • Schema::reIndex() was broken, works now
  • Schema::getIndices() was broken, works now
  • Schema::hasIndex() was broken, works now
  • Schema::getMappings() was broken, works now
  • Schema::getSettings() was broken, works now
  • Index Blueprint for IP addresses $this->ip('field_name') required an extra invalid parameter, fixed

Upgrades

  • Dependency upgrade to "elasticsearch/elasticsearch": "8.10" (from "8.7")
  • Connecter update
    • to include table() method required for User Auth
    • Automatic index prefixing required for schema-related functionality
    • Ability to setIndexPrefix() in the connector on the fly
  • Schema methods for create(), modify(), & setAnalyser() now returns the index in question
  • Code clean up in Model, Query builder and IndexInterpreter
  • Updated docs to include re-indexing example

New Feature

  • updateWithoutRefresh($attriubutes) - works the same as saveWithoutRefresh() & createWithoutRefresh()
  • Schema::getIndex('name') - returns the index with the settings and mappings
  • Index prefix can be overridden,
    ex: Schema::overridePrefix(null)->getIndex('my_index') - returns my_index
    ex: Schema::overridePrefix('something_else')->getIndex('my_index') - returns something_else_my_index

Full Changelog: v2.7.2...v2.7.3

v2.6.4

03 Nov 13:34

Choose a tag to compare

Bug fixes:

  • Geo filtering was always returning all fields, fixed
  • Searching across multiple fields was not honoring 'minShouldMatch()', fixed
  • Schema::reIndex() was broken, works now
  • Schema::getIndices() was broken, works now
  • Schema::hasIndex() was broken, works now
  • Schema::getMappings() was broken, works now
  • Schema::getSettings() was broken, works now
  • Index Blueprint for IP addresses $this->ip('field_name') required an extra invalid parameter, fixed

Upgrades

  • Dependency upgrade to "elasticsearch/elasticsearch": "8.10" (from "8.7")
  • Connecter update
    • to include table() method required for User Auth
    • Automatic index prefixing required for schema-related functionality
    • Ability to setIndexPrefix() in the connector on the fly
  • Schema methods for create(), modify(), & setAnalyser() now returns the index in question
  • Code clean up in Model, Query builder and IndexInterpreter
  • Updated docs to include re-indexing example

New Feature

  • updateWithoutRefresh($attriubutes) - works the same as saveWithoutRefresh() & createWithoutRefresh()
  • Schema::getIndex('name') - returns the index with the settings and mappings
  • Index prefix can be overridden,
    ex: Schema::overridePrefix(null)->getIndex('my_index') - returns my_index
    ex: Schema::overridePrefix('something_else')->getIndex('my_index') - returns something_else_my_index

Full Changelog: v2.6.3...v2.6.4

v1.9.3

03 Nov 13:23

Choose a tag to compare

Bug fixes:

  • Geo filtering was always returning all fields, fixed
  • Searching across multiple fields was not honoring 'minShouldMatch()', fixed
  • Schema::reIndex() was broken, works now
  • Schema::getIndices() was broken, works now
  • Schema::hasIndex() was broken, works now
  • Schema::getMappings() was broken, works now
  • Schema::getSettings() was broken, works now
  • Index Blueprint for IP addresses $this->ip('field_name') required an extra invalid paramter, fixed

Upgrades

  • Connecter update
    • to include table() method required for User Auth
    • Automatic index prefixing required for schema-related functionality
    • Ability to setIndexPrefix() in the connector on the fly
  • Schema methods for create(), modify(), * setAnalyser() now returns the index in question
  • Code clean up in Model, Query builder and IndexInterpreter
  • Updated docs to include re-indexing example

New Feature

  • updateWithoutRefresh($attriubutes) - works the same as saveWithoutRefresh() & createWithoutRefresh()
  • Schema::getIndex('name') - returns the index with the settings and mappings
  • Index prefix can be overridden,
    ex: Schema::overridePrefix(null)->getIndex('my_index') - returns my_index
    ex: Schema::overridePrefix('something_else')->getIndex('my_index') - returns something_else_my_index

Full Changelog: v1.9.2...v1.9.3

v1.8.2

03 Nov 13:19

Choose a tag to compare

Bug fixes:

  • Geo filtering was always returning all fields, fixed
  • Searching across multiple fields was not honoring 'minShouldMatch()', fixed
  • Schema::reIndex() was broken, works now
  • Schema::getIndices() was broken, works now
  • Schema::hasIndex() was broken, works now
  • Schema::getMappings() was broken, works now
  • Schema::getSettings() was broken, works now
  • Index Blueprint for IP addresses $this->ip('field_name') required an extra invalid paramter, fixed

Upgrades

  • Connecter update
    • to include table() method required for User Auth
    • Automatic index prefixing required for schema-related functionality
    • Ability to setIndexPrefix() in the connector on the fly
  • Schema methods for create(), modify(), * setAnalyser() now returns the index in question
  • Code clean up in Model, Query builder and IndexInterpreter
  • Updated docs to include re-indexing example

New Feature

  • updateWithoutRefresh($attriubutes) - works the same as saveWithoutRefresh() & createWithoutRefresh()
  • Schema::getIndex('name') - returns the index with the settings and mappings
  • Index prefix can be overridden,
    ex: Schema::overridePrefix(null)->getIndex('my_index') - returns my_index
    ex: Schema::overridePrefix('something_else')->getIndex('my_index') - returns something_else_my_index

Full Changelog: v1.8.1...v1.8.2

v2.10.1

20 Oct 16:02

Choose a tag to compare

Bug Fix: Query escape rebuild to support non-Latin character sets

v2.9.3

20 Oct 15:57

Choose a tag to compare

Bug Fix: Query escape rebuild to support non-Latin character sets