# Get top query statistics

- Operation ID: `GetQueriesTop`
- HTTP method: `GET`
- Path: `/search/v2/indices/{indexId}/stats/queries/top`
- [Human-readable API reference](https://hub.synerise.com/api-reference/ai-search#tag/Search-Stats/operation/GetQueriesTop)

## Self-contained OpenAPI method

The fenced document below contains this method's documentation and all of its local references. It is self-contained; no category or master specification fetch is required.

```yaml
openapi: 3.0.0
info:
  title: Synerise Public API
  version: 1.9.1
paths:
  /search/v2/indices/{indexId}/stats/queries/top:
    get:
      summary: Get top query statistics
      description: |
        Retrieves the 1000 most popular queries. 

        <strong>IMPORTANT</strong>: Don't use this endpoint for displaying most popular queries to end users when they're searching. Instead, use [`search/v2/indices/{indexId}/list`](https://developers.synerise.com/AISearch/AISearch.html#operation/ListingGet), where `indexId` is a suggestion index.


        ---

        **API consumers:** <a href="/api-reference/authorization?tag=Authorization&amp;operationId=profileLogin" target="_blank" rel="noopener">Workspace (Business Profile)</a>, <a href="/api-reference/authorization?tag=Authorization&amp;operationId=userLogin" target="_blank" rel="noopener">Synerise User</a>, <span title="Deprecated">AI API key (legacy)</span>

        **API key permission required:** `AI_STATS_READ`

        **User role permission required:** `assets_search: read`
      operationId: GetQueriesTop
      tags:
        - Search Stats
      security:
        - JWT: []
        - TrackerKey: []
      parameters:
        - name: indexId
          in: path
          required: true
          description: ID of the index for which the stats are requested
          schema:
            type: string
            example: 4add1a1fa877c1651906bb22c9dfd37a1618852272
        - name: dateFrom
          in: query
          required: false
          description: |
            Upper bound of the interval for which the statistics will be retrieved.  
            Must be provided with `to`, otherwise the filter is treated as unspecified.  
            If not specified, the interval is last 7 days.
          schema:
            type: string
            format: date
        - name: dateTo
          in: query
          required: false
          description: |
            Lower bound of the interval for which the statistics will be retrieved.
            If not specified, the interval is last 7 days.
          schema:
            type: string
            format: date
        - name: query
          in: query
          required: false
          description: Query for which stats will be returned. If not provided, the results are returned for the most popular queries.
          schema:
            type: string
        - name: searchType
          in: query
          required: false
          description: Search type for which stats will be retrieved.
          schema:
            type: string
            default: all
            enum:
              - fullTextSearch
              - autocomplete
              - listing
              - visual
              - all
        - name: queryFilter
          in: query
          required: false
          description: Queries for which stats will be retrieved.
          schema:
            type: string
            default: queries
            enum:
              - queries
              - queriesWithNoResults
              - queriesWithUsedSuggestions
        - name: groupBy
          in: query
          required: false
          description: Attribute for which retrieved stats will be grouped.
          schema:
            type: string
            enum:
              - date
        - name: withFilters
          in: query
          required: false
          description: Switch to display search statistics with enabled filters or without filters.
          schema:
            type: string
            enum:
              - true
              - false
        - name: SortBy
          in: query
          required: false
          description: Field by which results should be sorted.
          schema:
            type: string
            default: count
            enum:
              - count
              - clicks
              - conversions
              - clickThroughRate
              - revenue
              - conversionRate
        - name: ordering
          in: query
          required: false
          description: Sort order direction.
          schema:
            type: string
            default: desc
            enum:
              - asc
              - desc
      responses:
        "200":
          description: Statistics returned
          content:
            application/json:
              schema:
                type: object
                description: |
                  Response envelope for `GetQueriesTop`. The `data` field carries
                  the ranked list of top queries (up to 1000) for one search index.
                required:
                  - data
                properties:
                  data:
                    type: array
                    description: Top queries
                    items:
                      type: object
                      properties:
                        query:
                          type: string
                          description: Query used for search.
                        count:
                          type: integer
                          description: The number of times the search was performed.
                        clicks:
                          type: integer
                          description: The number of times a result was clicked.
                        clickThroughRate:
                          type: number
                          format: float
                          description: CTR of the search.
                        revenue:
                          type: number
                          format: float
                          description: Revenue generated from the search.
                        conversions:
                          type: integer
                          description: The number of successful conversions.
                        conversionRate:
                          type: number
                          format: float
                          description: Conversion rate of the search.
        "500":
          description: Service error
          content:
            application/json:
              schema:
                type: object
                properties:
                  httpStatus:
                    type: integer
                    example: 500
                    description: HTTP status of the error.
                  errorCode:
                    type: integer
                    description: Status code. See [error reference](https://developers.synerise.com/errors.html).
                  timestamp:
                    type: string
                    format: date-time
                    description: Time when the error occurred.
                  message:
                    type: string
                    description: Description of the problem.
                  traceId:
                    type: string
                    description: Trace ID for debugging.
                  help:
                    type: string
                    description: Currently unused.
        4xx:
          description: Incorrect request
          content:
            application/json:
              schema:
                type: object
                properties:
                  httpStatus:
                    type: integer
                    example: 500
                    description: HTTP status of the error.
                  errorCode:
                    type: integer
                    description: Status code. See [error reference](https://developers.synerise.com/errors.html).
                  timestamp:
                    type: string
                    format: date-time
                    description: Time when the error occurred.
                  message:
                    type: string
                    description: Description of the problem.
                  traceId:
                    type: string
                    description: Trace ID for debugging.
                  help:
                    type: string
                    description: Currently unused.
      x-snr-doc-urls:
        - /api-reference/ai-search#tag/Search-Stats/operation/GetQueriesTop
      x-codeSamples:
        - lang: cURL
          label: cURL
          source: |-
            curl --request GET \
              --url 'https://api.synerise.com/search/v2/indices/4add1a1fa877c1651906bb22c9dfd37a1618852272/stats/queries/top?dateFrom=SOME_STRING_VALUE&dateTo=SOME_STRING_VALUE&query=SOME_STRING_VALUE&searchType=SOME_STRING_VALUE&queryFilter=SOME_STRING_VALUE&groupBy=SOME_STRING_VALUE&withFilters=SOME_STRING_VALUE&SortBy=SOME_STRING_VALUE&ordering=SOME_STRING_VALUE' \
              --header 'Authorization: Bearer REPLACE_BEARER_TOKEN'
        - lang: Python
          label: Python
          source: |-
            import http.client

            conn = http.client.HTTPSConnection("api.synerise.com")

            headers = { 'Authorization': "Bearer REPLACE_BEARER_TOKEN" }

            conn.request("GET", "/search/v2/indices/4add1a1fa877c1651906bb22c9dfd37a1618852272/stats/queries/top?dateFrom=SOME_STRING_VALUE&dateTo=SOME_STRING_VALUE&query=SOME_STRING_VALUE&searchType=SOME_STRING_VALUE&queryFilter=SOME_STRING_VALUE&groupBy=SOME_STRING_VALUE&withFilters=SOME_STRING_VALUE&SortBy=SOME_STRING_VALUE&ordering=SOME_STRING_VALUE", headers=headers)

            res = conn.getresponse()
            data = res.read()

            print(data.decode("utf-8"))
        - lang: JavaScript
          label: JavaScript
          source: |-
            const data = null;

            const xhr = new XMLHttpRequest();
            xhr.withCredentials = true;

            xhr.addEventListener("readystatechange", function () {
              if (this.readyState === this.DONE) {
                console.log(this.responseText);
              }
            });

            xhr.open("GET", "https://api.synerise.com/search/v2/indices/4add1a1fa877c1651906bb22c9dfd37a1618852272/stats/queries/top?dateFrom=SOME_STRING_VALUE&dateTo=SOME_STRING_VALUE&query=SOME_STRING_VALUE&searchType=SOME_STRING_VALUE&queryFilter=SOME_STRING_VALUE&groupBy=SOME_STRING_VALUE&withFilters=SOME_STRING_VALUE&SortBy=SOME_STRING_VALUE&ordering=SOME_STRING_VALUE");
            xhr.setRequestHeader("Authorization", "Bearer REPLACE_BEARER_TOKEN");

            xhr.send(data);
        - lang: Node.js
          label: Node.js
          source: |-
            const http = require("https");

            const options = {
              "method": "GET",
              "hostname": "api.synerise.com",
              "port": null,
              "path": "/search/v2/indices/4add1a1fa877c1651906bb22c9dfd37a1618852272/stats/queries/top?dateFrom=SOME_STRING_VALUE&dateTo=SOME_STRING_VALUE&query=SOME_STRING_VALUE&searchType=SOME_STRING_VALUE&queryFilter=SOME_STRING_VALUE&groupBy=SOME_STRING_VALUE&withFilters=SOME_STRING_VALUE&SortBy=SOME_STRING_VALUE&ordering=SOME_STRING_VALUE",
              "headers": {
                "Authorization": "Bearer REPLACE_BEARER_TOKEN"
              }
            };

            const req = http.request(options, function (res) {
              const chunks = [];

              res.on("data", function (chunk) {
                chunks.push(chunk);
              });

              res.on("end", function () {
                const body = Buffer.concat(chunks);
                console.log(body.toString());
              });
            });

            req.end();
        - lang: PHP
          label: PHP
          source: |-
            <?php

            $request = new HttpRequest();
            $request->setUrl('https://api.synerise.com/search/v2/indices/4add1a1fa877c1651906bb22c9dfd37a1618852272/stats/queries/top');
            $request->setMethod(HTTP_METH_GET);

            $request->setQueryData([
              'dateFrom' => 'SOME_STRING_VALUE',
              'dateTo' => 'SOME_STRING_VALUE',
              'query' => 'SOME_STRING_VALUE',
              'searchType' => 'SOME_STRING_VALUE',
              'queryFilter' => 'SOME_STRING_VALUE',
              'groupBy' => 'SOME_STRING_VALUE',
              'withFilters' => 'SOME_STRING_VALUE',
              'SortBy' => 'SOME_STRING_VALUE',
              'ordering' => 'SOME_STRING_VALUE'
            ]);

            $request->setHeaders([
              'Authorization' => 'Bearer REPLACE_BEARER_TOKEN'
            ]);

            try {
              $response = $request->send();

              echo $response->getBody();
            } catch (HttpException $ex) {
              echo $ex;
            }
        - lang: Java
          label: Java
          source: |-
            HttpResponse<String> response = Unirest.get("https://api.synerise.com/search/v2/indices/4add1a1fa877c1651906bb22c9dfd37a1618852272/stats/queries/top?dateFrom=SOME_STRING_VALUE&dateTo=SOME_STRING_VALUE&query=SOME_STRING_VALUE&searchType=SOME_STRING_VALUE&queryFilter=SOME_STRING_VALUE&groupBy=SOME_STRING_VALUE&withFilters=SOME_STRING_VALUE&SortBy=SOME_STRING_VALUE&ordering=SOME_STRING_VALUE")
              .header("Authorization", "Bearer REPLACE_BEARER_TOKEN")
              .asString();
servers:
  - description: Microsoft Azure EU
    url: https://api.synerise.com
  - description: Microsoft Azure USA
    url: https://api.azu.synerise.com
  - description: Google Cloud Platform
    url: https://api.geb.synerise.com
tags:
  - name: Search Stats
components:
  securitySchemes:
    JWT:
      type: http
      scheme: bearer
      description: |-
        JWT Bearer token. The header looks like this: `Bearer {JWT}`

        Remember to include the space between 'Bearer' and the token.

        Generate a token via the **Authorization** endpoints.
    TrackerKey:
      type: apiKey
      name: token
      in: query
      description: Authorization by tracker key sent as a query parameter. This is the same key as used in the website tracking code.
```
