manticoresoftware / manticoresearch-typescript

Official TypeScript client for Manticore Search
MIT License
8 stars 3 forks source link

Fix `aggs` and `expressions` in `SearchRequest` #3

Closed schwarmco closed 10 months ago

schwarmco commented 10 months ago

Edit: After further testing, it turns out, that some types (i tried to use) are incorrect - here are failing test cases:

describe('Search Api Tests', () => {
  it('should aggregate by field', async function () {
    try {
      const query: Manticoresearch.SearchRequest = {
        index: 'test',
        query: {
          match_all: {},
        },
        aggs: [
          {
            name: 'cat',
            field: 'cat',
          },
        ],
      };

      const result = await searchApi.search(query);
      expect(result).to.deep.nested.property('hits.total', 5);
    } catch (err) {
      const errorResponse = err instanceof Manticoresearch.ResponseError ? await err.response.json() : err;
      console.error('Error response:', JSON.stringify(errorResponse, null, 2));
      expect(err).to.be.null;
    }
  });
});

which results in this error on manticoresearch 6.2.12:

{
      "total": 0,
      "warning": "",
      "error": "\"aggs\" property should be an object\""
}

According to the documentation, the schema should look like this instead:

"aggs": {
    "group name" : {
        "terms" : {
            "field":"attribute name",
            "size": 1000
      },
      "sort": [ {"attribute name": { "order":"asc" }} ]
  }
}

cc @sanikolaev - is there a documentation for the complete json-api schema?

While creating these test cases i've also stumbled upon some issues (or at least "you have to know"s) when migrating from the javascript library:

utilsApi.sql('drop table if exists test');

works in the javascript library, but throws this error in typescript:

{
  "error": "only SELECT queries are supported"
}

because the rawResponse option defaults to true in javascript, but false in typescript.

I'd be happy to contribute to this library (e.g. creating a PR with the updated types for aggs and expressions and updating the test cases) but there seems to be a lot of things not being right yet. The PR #2 of @mannol tidies up some things though.

Let me know what are your thoughts on this, if you accept PRs and how to contribute.

I want to order a facet result by the document counts to get my "most used buckets" like its described here: https://manual.manticoresearch.com/Searching/Faceted_search#Ordering-in-facet-result

Currently the Aggregation-Type only has name, field and size.

sanikolaev commented 10 months ago

cc @sanikolaev - is there a documentation for the complete json-api schema?

Please see https://manual.manticoresearch.com/Openapi#OpenAPI-specification

Let me know what are your thoughts on this

Calling @Nick-S-2018 to advise on this.

I'd be happy to contribute to this library (e.g. creating a PR with the updated types for aggs and expressions and updating the test cases) but there seems to be a lot of things not being right yet. The PR https://github.com/manticoresoftware/manticoresearch-typescript/pull/2 of @mannol tidies up some things though.

Sure thing we accept PRs. Any contribution will be highly appreciated.

schwarmco commented 10 months ago

Thanks @sanikolaev for pointing to the OpenAPI specs which actually pointed me to the whole OpenAPI-based client generation repo (https://github.com/manticoresoftware/openapi) - so PRs should probably go there?!

anyway, it seems the OpenAPI spec itself is incorrect, specifying aggs and expressions as an array:

https://github.com/manticoresoftware/openapi/blob/master/manticore.yml#L625-L632

sanikolaev commented 10 months ago

so PRs should probably go there?!

Yes.

anyway, it seems the OpenAPI spec itself is incorrect, specifying aggs and expressions as an array:

I'll check with the team on this.