> ## Documentation Index
> Fetch the complete documentation index at: https://www.algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# (Beta) Query a metrics time series

> Beta: this endpoint is under active development and may change without notice.

**Required ACL:** `analytics`

Returns one time series per `groupBy` combination, each with period `totals` and a per-day metric
breakdown. `metrics` and `parameters` are required; `groupBy` and `filters` are optional. Discover
valid field kinds per domain with `/3/patterns/fields`.

## Usage

<CodeGroup>
  ```cs C# theme={"system"}
  // Initialize the client
  var client = new AnalyticsClient(
    new AnalyticsConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION")
  );

  // Call the API
  var response = await client.QueryPatternsTimeseriesAsync(
    new TimeseriesPayload
    {
      Metrics = new List<FieldReference> { new FieldReference { Kind = "searchesCount" } },
      Parameters = new List<ParameterDefinition>
      {
        new ParameterDefinition
        {
          Kind = "indices",
          Value = new ParameterValue(new List<string> { "index" }),
        },
      },
    },
    "index"
  );

  // print the response
  Console.WriteLine(response);
  ```

  ```go Go theme={"system"}
  // Initialize the client with your application region, eg. analytics.ALGOLIA_APPLICATION_REGION
  client, err := analytics.NewClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", analytics.US)
  if err != nil {
    // The client can fail to initialize if you pass an invalid parameter.
    panic(err)
  }

  // Call the API
  response, err := client.QueryPatternsTimeseries(client.NewApiQueryPatternsTimeseriesRequest(

    analytics.NewEmptyTimeseriesPayload().SetMetrics(
      []analytics.FieldReference{*analytics.NewEmptyFieldReference().SetKind("searchesCount")}).SetParameters(
      []analytics.ParameterDefinition{
        *analytics.NewEmptyParameterDefinition().SetKind("indices").SetValue(analytics.ArrayOfStringAsParameterValue(
          []string{"index"})),
      }),
  ).WithIndex("index"))
  if err != nil {
    // handle the eventual error
    panic(err)
  }


  // print the response
  print(response)
  ```

  ```java Java theme={"system"}
  // Initialize the client
  AnalyticsClient client = new AnalyticsClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION");

  // Call the API
  TimeseriesResponse response = client.queryPatternsTimeseries(
    new TimeseriesPayload()
      .setMetrics(Arrays.asList(new FieldReference().setKind("searchesCount")))
      .setParameters(Arrays.asList(new ParameterDefinition().setKind("indices").setValue(ParameterValue.of(Arrays.asList("index"))))),
    "index"
  );

  // print the response
  System.out.println(response);
  ```

  ```js JavaScript theme={"system"}
  // Initialize the client
  // Replace 'us' with your Algolia Application Region
  const client = algoliasearch('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY').initAnalytics({ region: 'us' });

  // Call the API
  const response = await client.queryPatternsTimeseries({
    timeseriesPayload: { metrics: [{ kind: 'searchesCount' }], parameters: [{ kind: 'indices', value: ['index'] }] },
    index: 'index',
  });


  // print the response
  console.log(response);
  ```

  ```kotlin Kotlin theme={"system"}
  // Initialize the client
  val client =
    AnalyticsClient(
      appId = "ALGOLIA_APPLICATION_ID",
      apiKey = "ALGOLIA_API_KEY",
      region = "ALGOLIA_APPLICATION_REGION",
    )

  // Call the API
  var response =
    client.queryPatternsTimeseries(
      timeseriesPayload =
        TimeseriesPayload(
          metrics = listOf(FieldReference(kind = "searchesCount")),
          parameters =
            listOf(
              ParameterDefinition(kind = "indices", value = ParameterValue.of(listOf("index")))
            ),
        ),
      index = "index",
    )


  // print the response
  println(response)
  ```

  ```php PHP theme={"system"}
  // Initialize the client
  $client = AnalyticsClient::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY', 'ALGOLIA_APPLICATION_REGION');

  // Call the API
  $response = $client->queryPatternsTimeseries(
      ['metrics' => [
          ['kind' => 'searchesCount',
          ],
      ],
          'parameters' => [
              ['kind' => 'indices',
                  'value' => [
                      'index',
                  ],
              ],
          ],
      ],
      'index',
  );


  // print the response
  var_dump($response);
  ```

  ```python Python theme={"system"}
  # Initialize the client
  # In an asynchronous context, you can use AnalyticsClient instead, which exposes the exact same methods.
  client = AnalyticsClientSync(
      "ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION"
  )

  # Call the API
  response = client.query_patterns_timeseries(
      timeseries_payload={
          "metrics": [
              {
                  "kind": "searchesCount",
              },
          ],
          "parameters": [
              {
                  "kind": "indices",
                  "value": [
                      "index",
                  ],
              },
          ],
      },
      index="index",
  )


  # print the response
  print(response)
  ```

  ```ruby Ruby theme={"system"}
  # Initialize the client
  client = Algolia::AnalyticsClient.create("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION")

  # Call the API
  response = client.query_patterns_timeseries(
    Algolia::Analytics::TimeseriesPayload.new(
      metrics: [Algolia::Analytics::FieldReference.new(kind: "searchesCount")],
      parameters: [Algolia::Analytics::ParameterDefinition.new(kind: "indices", value: ["index"])]
    ),
    "index"
  )


  # print the response
  puts(response)
  ```

  ```scala Scala theme={"system"}
  // Initialize the client
  val client = AnalyticsClient(
    appId = "ALGOLIA_APPLICATION_ID",
    apiKey = "ALGOLIA_API_KEY",
    region = Option("ALGOLIA_APPLICATION_REGION")
  )

  // Call the API
  val response = Await.result(
    client.queryPatternsTimeseries(
      timeseriesPayload = TimeseriesPayload(
        metrics = Seq(
          FieldReference(
            kind = "searchesCount"
          )
        ),
        parameters = Seq(
          ParameterDefinition(
            kind = "indices",
            value = ParameterValue(Seq("index"))
          )
        )
      ),
      index = Some("index")
    ),
    Duration(100, "sec")
  )

  // print the response
  println(response)
  ```

  ```swift Swift theme={"system"}
  // Initialize the client
  let client = try AnalyticsClient(appID: "ALGOLIA_APPLICATION_ID", apiKey: "ALGOLIA_API_KEY", region: .us)

  // Call the API
  let response = try await client.queryPatternsTimeseries(
      timeseriesPayload: TimeseriesPayload(
          metrics: [FieldReference(kind: "searchesCount")],
          parameters: [ParameterDefinition(
              kind: "indices",
              value: ParameterValue.arrayOfString(["index"])
          )]
      ),
      index: "index"
  )

  // print the response
  print(response)
  ```
</CodeGroup>

<Card icon="folder-code" horizontal="true" title="See the full API reference" arrow="true" href="/doc/rest-api/analytics/query-patterns-timeseries">
  For more details about input parameters
  and response fields.
</Card>
