Skip to content

Commit

Permalink
Implemented composite aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
nick committed Apr 13, 2024
1 parent d7c01f3 commit 071d81e
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 31 deletions.
1 change: 1 addition & 0 deletions docs/Aggregation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**terms** | [**AggregationTerms**](AggregationTerms.md) | | [optional]
**sort** | **[{String: AggregationSortInnerValue}]** | | [optional]
**composite** | [**AggregationComposite**](AggregationComposite.md) | | [optional]

[[Using in search requests]](SearchRequest.md#Aggregation)

Expand Down
12 changes: 12 additions & 0 deletions docs/AggregationComposite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Manticoresearch.AggregationComposite

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**size** | **Number** | Maximum number of composite buckets in the result | [optional]
**sources** | **[{String: AggregationCompositeSourcesInnerValue}]** | | [optional]




11 changes: 11 additions & 0 deletions docs/AggregationCompositeSourcesInnerValue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Manticoresearch.AggregationCompositeSourcesInnerValue

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**terms** | [**AggregationCompositeSourcesInnerValueTerms**](AggregationCompositeSourcesInnerValueTerms.md) | | [optional]




11 changes: 11 additions & 0 deletions docs/AggregationCompositeSourcesInnerValueTerms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Manticoresearch.AggregationCompositeSourcesInnerValueTerms

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**field** | **String** | Name of attribute to aggregate by | [optional]




4 changes: 2 additions & 2 deletions docs/AggregationTerms.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**field** | **String** | Attribute Name to Aggregate | [optional]
**size** | **Number** | Maximum Number of Buckets in the Result | [optional]
**field** | **String** | Name of attribute to aggregate by | [optional]
**size** | **Number** | Maximum number of buckets in the result | [optional]



Expand Down
15 changes: 15 additions & 0 deletions docs/SearchRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ var agg2 = new Manticoresearch.Aggregation();
agg2['terms'] = Manticoresearch.AggregationTerms.constructFromObject({field: 'rating'});
searchRequest.aggs['agg2'] = agg2;

async function(){
var res = await searchApi.search(searchRequest);
console.log(JSON.stringify(res, null, 4));
}

// Composite aggregation example
var compAggTerms1 = Manticoresearch.AggregationCompositeSourcesInnerValueTerms.constructFromObject({field: '_year'});
var compAgg1 = Manticoresearch.AggregationCompositeSourcesInnerValue.constructFromObject({'terms': compAggTerms1})
var compAggTerms2 = Manticoresearch.AggregationCompositeSourcesInnerValueTerms.constructFromObject({field: 'rating'});
var compAgg2 = Manticoresearch.AggregationCompositeSourcesInnerValue.constructFromObject({'terms': compAggTerms2});
var compSources = [{'comp_agg_1': compAgg1}, {'comp_agg_2': compAgg2}];
var compAgg = Manticoresearch.AggregationComposite.constructFromObject({'size': 5, 'sources': compSources});
var agg = Manticoresearch.Aggregation.constructFromObject({'composite': compAgg});
searchRequest.aggs = {'comp_agg': agg};

async function(){
var res = await searchApi.search(searchRequest);
console.log(JSON.stringify(res, null, 4));
Expand Down
21 changes: 18 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
(function(factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['ApiClient', 'model/Aggregation', 'model/AggregationSortInnerValue', 'model/AggregationTerms', 'model/BoolFilter', 'model/BulkResponse', 'model/DeleteDocumentRequest', 'model/DeleteResponse', 'model/EqualsFilter', 'model/ErrorResponse', 'model/Facet', 'model/FilterBoolean', 'model/FilterNumber', 'model/FilterString', 'model/GeoDistanceFilter', 'model/GeoDistanceFilterLocationAnchor', 'model/Highlight', 'model/HighlightField', 'model/InFilter', 'model/InsertDocumentRequest', 'model/KnnQueryByDocId', 'model/KnnQueryByVector', 'model/MatchFilter', 'model/MatchOp', 'model/MatchOpFilter', 'model/MatchPhraseFilter', 'model/NotFilterBoolean', 'model/NotFilterNumber', 'model/NotFilterString', 'model/PercolateRequest', 'model/PercolateRequestQuery', 'model/QueryFilter', 'model/RangeFilter', 'model/ReplaceDocumentRequest', 'model/SearchRequest', 'model/SearchRequestKnn', 'model/SearchResponse', 'model/SearchResponseHits', 'model/SortMVA', 'model/SortMultiple', 'model/SortOrder', 'model/SourceByRules', 'model/SuccessResponse', 'model/UpdateDocumentRequest', 'model/UpdateResponse', 'api/IndexApi', 'api/SearchApi', 'api/UtilsApi'], factory);
define(['ApiClient', 'model/Aggregation', 'model/AggregationComposite', 'model/AggregationCompositeSourcesInnerValue', 'model/AggregationCompositeSourcesInnerValueTerms', 'model/AggregationSortInnerValue', 'model/AggregationTerms', 'model/BoolFilter', 'model/BulkResponse', 'model/DeleteDocumentRequest', 'model/DeleteResponse', 'model/EqualsFilter', 'model/ErrorResponse', 'model/Facet', 'model/FilterBoolean', 'model/FilterNumber', 'model/FilterString', 'model/GeoDistanceFilter', 'model/GeoDistanceFilterLocationAnchor', 'model/Highlight', 'model/HighlightField', 'model/InFilter', 'model/InsertDocumentRequest', 'model/MatchFilter', 'model/MatchOp', 'model/MatchOpFilter', 'model/MatchPhraseFilter', 'model/NotFilterBoolean', 'model/NotFilterNumber', 'model/NotFilterString', 'model/PercolateRequest', 'model/PercolateRequestQuery', 'model/QueryFilter', 'model/RangeFilter', 'model/ReplaceDocumentRequest', 'model/SearchRequest', 'model/SearchResponse', 'model/SearchResponseHits', 'model/SortMVA', 'model/SortMultiple', 'model/SortOrder', 'model/SourceByRules', 'model/SuccessResponse', 'model/UpdateDocumentRequest', 'model/UpdateResponse', 'api/IndexApi', 'api/SearchApi', 'api/UtilsApi'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
module.exports = factory(require('./ApiClient'), require('./model/Aggregation'), require('./model/AggregationSortInnerValue'), require('./model/AggregationTerms'), require('./model/BoolFilter'), require('./model/BulkResponse'), require('./model/DeleteDocumentRequest'), require('./model/DeleteResponse'), require('./model/EqualsFilter'), require('./model/ErrorResponse'), require('./model/Facet'), require('./model/FilterBoolean'), require('./model/FilterNumber'), require('./model/FilterString'), require('./model/GeoDistanceFilter'), require('./model/GeoDistanceFilterLocationAnchor'), require('./model/Highlight'), require('./model/HighlightField'), require('./model/InFilter'), require('./model/InsertDocumentRequest'), require('./model/KnnQueryByDocId'), require('./model/KnnQueryByVector'), require('./model/MatchFilter'), require('./model/MatchOp'), require('./model/MatchOpFilter'), require('./model/MatchPhraseFilter'), require('./model/NotFilterBoolean'), require('./model/NotFilterNumber'), require('./model/NotFilterString'), require('./model/PercolateRequest'), require('./model/PercolateRequestQuery'), require('./model/QueryFilter'), require('./model/RangeFilter'), require('./model/ReplaceDocumentRequest'), require('./model/SearchRequest'), require('./model/SearchRequestKnn'), require('./model/SearchResponse'), require('./model/SearchResponseHits'), require('./model/SortMVA'), require('./model/SortMultiple'), require('./model/SortOrder'), require('./model/SourceByRules'), require('./model/SuccessResponse'), require('./model/UpdateDocumentRequest'), require('./model/UpdateResponse'), require('./api/IndexApi'), require('./api/SearchApi'), require('./api/UtilsApi'));
module.exports = factory(require('./ApiClient'), require('./model/Aggregation'), require('./model/AggregationComposite'), require('./model/AggregationCompositeSourcesInnerValue'), require('./model/AggregationCompositeSourcesInnerValueTerms'), require('./model/AggregationSortInnerValue'), require('./model/AggregationTerms'), require('./model/BoolFilter'), require('./model/BulkResponse'), require('./model/DeleteDocumentRequest'), require('./model/DeleteResponse'), require('./model/EqualsFilter'), require('./model/ErrorResponse'), require('./model/Facet'), require('./model/FilterBoolean'), require('./model/FilterNumber'), require('./model/FilterString'), require('./model/GeoDistanceFilter'), require('./model/GeoDistanceFilterLocationAnchor'), require('./model/Highlight'), require('./model/HighlightField'), require('./model/InFilter'), require('./model/InsertDocumentRequest'), require('./model/MatchFilter'), require('./model/MatchOp'), require('./model/MatchOpFilter'), require('./model/MatchPhraseFilter'), require('./model/NotFilterBoolean'), require('./model/NotFilterNumber'), require('./model/NotFilterString'), require('./model/PercolateRequest'), require('./model/PercolateRequestQuery'), require('./model/QueryFilter'), require('./model/RangeFilter'), require('./model/ReplaceDocumentRequest'), require('./model/SearchRequest'), require('./model/SearchResponse'), require('./model/SearchResponseHits'), require('./model/SortMVA'), require('./model/SortMultiple'), require('./model/SortOrder'), require('./model/SourceByRules'), require('./model/SuccessResponse'), require('./model/UpdateDocumentRequest'), require('./model/UpdateResponse'), require('./api/IndexApi'), require('./api/SearchApi'), require('./api/UtilsApi'));
}
}(function(ApiClient, Aggregation, AggregationSortInnerValue, AggregationTerms, BoolFilter, BulkResponse, DeleteDocumentRequest, DeleteResponse, EqualsFilter, ErrorResponse, Facet, FilterBoolean, FilterNumber, FilterString, GeoDistanceFilter, GeoDistanceFilterLocationAnchor, Highlight, HighlightField, InFilter, InsertDocumentRequest, KnnQueryByDocId, KnnQueryByVector, MatchFilter, MatchOp, MatchOpFilter, MatchPhraseFilter, NotFilterBoolean, NotFilterNumber, NotFilterString, PercolateRequest, PercolateRequestQuery, QueryFilter, RangeFilter, ReplaceDocumentRequest, SearchRequest, SearchRequestKnn, SearchResponse, SearchResponseHits, SortMVA, SortMultiple, SortOrder, SourceByRules, SuccessResponse, UpdateDocumentRequest, UpdateResponse, IndexApi, SearchApi, UtilsApi) {
}(function(ApiClient, Aggregation, AggregationComposite, AggregationCompositeSourcesInnerValue, AggregationCompositeSourcesInnerValueTerms, AggregationSortInnerValue, AggregationTerms, BoolFilter, BulkResponse, DeleteDocumentRequest, DeleteResponse, EqualsFilter, ErrorResponse, Facet, FilterBoolean, FilterNumber, FilterString, GeoDistanceFilter, GeoDistanceFilterLocationAnchor, Highlight, HighlightField, InFilter, InsertDocumentRequest, MatchFilter, MatchOp, MatchOpFilter, MatchPhraseFilter, NotFilterBoolean, NotFilterNumber, NotFilterString, PercolateRequest, PercolateRequestQuery, QueryFilter, RangeFilter, ReplaceDocumentRequest, SearchRequest, SearchResponse, SearchResponseHits, SortMVA, SortMultiple, SortOrder, SourceByRules, SuccessResponse, UpdateDocumentRequest, UpdateResponse, IndexApi, SearchApi, UtilsApi) {
'use strict';

/**
Expand Down Expand Up @@ -58,6 +58,21 @@
* @property {module:model/Aggregation}
*/
Aggregation: Aggregation,
/**
* The AggregationComposite model constructor.
* @property {module:model/AggregationComposite}
*/
AggregationComposite: AggregationComposite,
/**
* The AggregationCompositeSourcesInnerValue model constructor.
* @property {module:model/AggregationCompositeSourcesInnerValue}
*/
AggregationCompositeSourcesInnerValue: AggregationCompositeSourcesInnerValue,
/**
* The AggregationCompositeSourcesInnerValueTerms model constructor.
* @property {module:model/AggregationCompositeSourcesInnerValueTerms}
*/
AggregationCompositeSourcesInnerValueTerms: AggregationCompositeSourcesInnerValueTerms,
/**
* The AggregationSortInnerValue model constructor.
* @property {module:model/AggregationSortInnerValue}
Expand Down
15 changes: 11 additions & 4 deletions src/model/Aggregation.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['ApiClient', 'model/AggregationSortInnerValue', 'model/AggregationTerms'], factory);
define(['ApiClient', 'model/AggregationComposite', 'model/AggregationSortInnerValue', 'model/AggregationTerms'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
module.exports = factory(require('../ApiClient'), require('./AggregationSortInnerValue'), require('./AggregationTerms'));
module.exports = factory(require('../ApiClient'), require('./AggregationComposite'), require('./AggregationSortInnerValue'), require('./AggregationTerms'));
} else {
// Browser globals (root is window)
if (!root.Manticoresearch) {
root.Manticoresearch = {};
}
root.Manticoresearch.Aggregation = factory(root.Manticoresearch.ApiClient, root.Manticoresearch.AggregationSortInnerValue, root.Manticoresearch.AggregationTerms);
root.Manticoresearch.Aggregation = factory(root.Manticoresearch.ApiClient, root.Manticoresearch.AggregationComposite, root.Manticoresearch.AggregationSortInnerValue, root.Manticoresearch.AggregationTerms);
}
}(this, function(ApiClient, AggregationSortInnerValue, AggregationTerms) {
}(this, function(ApiClient, AggregationComposite, AggregationSortInnerValue, AggregationTerms) {
'use strict';


Expand Down Expand Up @@ -57,6 +57,9 @@
if (data.hasOwnProperty('sort')) {
obj['sort'] = ApiClient.convertToType(data['sort'], [{'String': AggregationSortInnerValue}]);
}
if (data.hasOwnProperty('composite')) {
obj['composite'] = AggregationComposite.constructFromObject(data['composite']);
}
}
return obj;
}
Expand All @@ -69,6 +72,10 @@
* @member {Array.<Object.<String, module:model/AggregationSortInnerValue>>} sort
*/
exports.prototype['sort'] = undefined;
/**
* @member {module:model/AggregationComposite} composite
*/
exports.prototype['composite'] = undefined;



Expand Down
79 changes: 79 additions & 0 deletions src/model/AggregationComposite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Manticore Search Client
* Copyright (c) 2020-2021, Manticore Software LTD (https://manticoresearch.com)
*
* All rights reserved
*/

(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['ApiClient', 'model/AggregationCompositeSourcesInnerValue'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
module.exports = factory(require('../ApiClient'), require('./AggregationCompositeSourcesInnerValue'));
} else {
// Browser globals (root is window)
if (!root.Manticoresearch) {
root.Manticoresearch = {};
}
root.Manticoresearch.AggregationComposite = factory(root.Manticoresearch.ApiClient, root.Manticoresearch.AggregationCompositeSourcesInnerValue);
}
}(this, function(ApiClient, AggregationCompositeSourcesInnerValue) {
'use strict';



/**
* The AggregationComposite model module.
* @module model/AggregationComposite
* @version 4.0.0
*/

/**
* Constructs a new <code>AggregationComposite</code>.
* Composite aggregation
* @alias module:model/AggregationComposite
* @class
*/
var exports = function() {
var _this = this;

};

/**
* Constructs a <code>AggregationComposite</code> from a plain JavaScript object, optionally creating a new instance.
* Copies all relevant properties from <code>data</code> to <code>obj</code> if supplied or a new instance if not.
* @param {Object} data The plain JavaScript object bearing properties of interest.
* @param {module:model/AggregationComposite} obj Optional instance to populate.
* @return {module:model/AggregationComposite} The populated <code>AggregationComposite</code> instance.
*/
exports.constructFromObject = function(data, obj) {
if (data) {
obj = obj || new exports();
if (data.hasOwnProperty('size')) {
obj['size'] = ApiClient.convertToType(data['size'], 'Number');
}
if (data.hasOwnProperty('sources')) {
obj['sources'] = ApiClient.convertToType(data['sources'], [{'String': AggregationCompositeSourcesInnerValue}]);
}
}
return obj;
}

/**
* Maximum number of composite buckets in the result
* @member {Number} size
*/
exports.prototype['size'] = undefined;
/**
* @member {Array.<Object.<String, module:model/AggregationCompositeSourcesInnerValue>>} sources
*/
exports.prototype['sources'] = undefined;



return exports;
}));


70 changes: 70 additions & 0 deletions src/model/AggregationCompositeSourcesInnerValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Manticore Search Client
* Copyright (c) 2020-2021, Manticore Software LTD (https://manticoresearch.com)
*
* All rights reserved
*/

(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['ApiClient', 'model/AggregationCompositeSourcesInnerValueTerms'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
module.exports = factory(require('../ApiClient'), require('./AggregationCompositeSourcesInnerValueTerms'));
} else {
// Browser globals (root is window)
if (!root.Manticoresearch) {
root.Manticoresearch = {};
}
root.Manticoresearch.AggregationCompositeSourcesInnerValue = factory(root.Manticoresearch.ApiClient, root.Manticoresearch.AggregationCompositeSourcesInnerValueTerms);
}
}(this, function(ApiClient, AggregationCompositeSourcesInnerValueTerms) {
'use strict';



/**
* The AggregationCompositeSourcesInnerValue model module.
* @module model/AggregationCompositeSourcesInnerValue
* @version 4.0.0
*/

/**
* Constructs a new <code>AggregationCompositeSourcesInnerValue</code>.
* @alias module:model/AggregationCompositeSourcesInnerValue
* @class
*/
var exports = function() {
var _this = this;

};

/**
* Constructs a <code>AggregationCompositeSourcesInnerValue</code> from a plain JavaScript object, optionally creating a new instance.
* Copies all relevant properties from <code>data</code> to <code>obj</code> if supplied or a new instance if not.
* @param {Object} data The plain JavaScript object bearing properties of interest.
* @param {module:model/AggregationCompositeSourcesInnerValue} obj Optional instance to populate.
* @return {module:model/AggregationCompositeSourcesInnerValue} The populated <code>AggregationCompositeSourcesInnerValue</code> instance.
*/
exports.constructFromObject = function(data, obj) {
if (data) {
obj = obj || new exports();
if (data.hasOwnProperty('terms')) {
obj['terms'] = AggregationCompositeSourcesInnerValueTerms.constructFromObject(data['terms']);
}
}
return obj;
}

/**
* @member {module:model/AggregationCompositeSourcesInnerValueTerms} terms
*/
exports.prototype['terms'] = undefined;



return exports;
}));


Loading

0 comments on commit 071d81e

Please sign in to comment.