diff --git a/lib/controllers/v1/observations_controller.js b/lib/controllers/v1/observations_controller.js index 3747d877..62af3101 100644 --- a/lib/controllers/v1/observations_controller.js +++ b/lib/controllers/v1/observations_controller.js @@ -235,6 +235,7 @@ ObservationsController.elasticResults = async function observationElasticResults && ( _.isEmpty( query.inverse_filters ) || excludingOnlyUserIDs ) && _.isEmpty( query.grouped_inverse_filters ) && _.isEqual( query.sort, { created_at: "desc" } ) + && _.isEmpty( req.query.aggs ) ) { const sourceParams = util.sourceParams( returnOnlyID ? ["id"] : { includes: opts.includes, @@ -1238,8 +1239,8 @@ ObservationsController.observationsObserverCounts = async req => { }; // attempting to account for inaccurate counts for queries with a small size // see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-shard-size - if ( ( ( aggSize * 1.5 ) + 10 ) < 200 ) { - countQuery.aggs.top_observers.terms.shard_size = 200; + if ( ( ( aggSize * 1.5 ) + 10 ) < 500 ) { + countQuery.aggs.top_observers.terms.shard_size = 500; } } countQuery.per_page = 0; @@ -1289,8 +1290,8 @@ ObservationsController.observationsSpeciesObserverCounts = async req => { }; // attempting to account for inaccurate counts for queries with a small size // see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-shard-size - if ( ( ( aggSize * 1.5 ) + 10 ) < 200 ) { - countQuery.aggs.user_taxa.terms.shard_size = 200; + if ( ( ( aggSize * 1.5 ) + 10 ) < 500 ) { + countQuery.aggs.user_taxa.terms.shard_size = 500; } if ( aggSize > 0 ) { countQuery.aggs.user_taxa.aggs = { diff --git a/lib/controllers/v1/taxa_controller.js b/lib/controllers/v1/taxa_controller.js index 9d4bd11f..e6b6255e 100644 --- a/lib/controllers/v1/taxa_controller.js +++ b/lib/controllers/v1/taxa_controller.js @@ -20,6 +20,9 @@ TaxaController.show = async req => { throw util.httpError( 422, "Too many IDs" ); } const filters = [{ terms: { id: ids } }]; + if ( req.query.rank_level ) { + filters.push( esClient.termFilter( "rank_level", req.query.rank_level ) ); + } return TaxaController.searchQuery( req, { filters, details: true, diff --git a/lib/views/swagger_v1.yml.ejs b/lib/views/swagger_v1.yml.ejs index 93efd08e..982a68b6 100644 --- a/lib/views/swagger_v1.yml.ejs +++ b/lib/views/swagger_v1.yml.ejs @@ -1691,6 +1691,7 @@ paths: corresponding taxa. A maximum of 30 results will be returned parameters: - $ref: "#/parameters/path_multi_id" + - $ref: "#/parameters/rank_level" tags: - Taxa responses: diff --git a/openapi/paths/v2/taxa/{id}.js b/openapi/paths/v2/taxa/{id}.js index 1dc7a184..81c267e4 100644 --- a/openapi/paths/v2/taxa/{id}.js +++ b/openapi/paths/v2/taxa/{id}.js @@ -22,6 +22,7 @@ module.exports = sendWrapper => { .meta( { in: "path" } ) .required( ) ), + transform( Joi.array( ).items( Joi.number( ) ).label( "rank_level" ).meta( { in: "query" } ) ), transform( Joi.string( ).label( "fields" ).meta( { in: "query" } ) ), transform( Joi.string( ).label( "X-HTTP-Method-Override" ).meta( { in: "header" } ) ) ], diff --git a/openapi/schema/request/taxa_search.js b/openapi/schema/request/taxa_search.js index 3e81c773..edbd1340 100644 --- a/openapi/schema/request/taxa_search.js +++ b/openapi/schema/request/taxa_search.js @@ -32,7 +32,7 @@ module.exports = Joi.object( ).keys( { "variety", "form" ) ), - rank_level: Joi.number( ), + rank_level: Joi.array( ).items( Joi.number( ) ), id_above: Joi.number( ).integer( ), id_below: Joi.number( ).integer( ), per_page: Joi.number( ).integer( ), diff --git a/test/integration/v1/observations.js b/test/integration/v1/observations.js index bff8fd7c..9a54da9e 100644 --- a/test/integration/v1/observations.js +++ b/test/integration/v1/observations.js @@ -1329,6 +1329,13 @@ describe( "Observations", ( ) => { } ).expect( "Content-Type", /json/ ) .expect( 200, done ); } ); + + it( "can filter on id alone", function ( done ) { + request( this.app ).get( "/v1/observations/observers?id=1" ).expect( res => { + expect( res.body.total_results ).to.eq( 1 ); + } ).expect( "Content-Type", /json/ ) + .expect( 200, done ); + } ); } ); describe( "species_counts", ( ) => {