Counts

Returns the number of clicks and total number of queries in ascending order.

One day is the default block of time and the default time/date format is RFC3339.

GET /api/as/v1/engines/{ENGINE_NAME}/analytics/clicks
POST /api/as/v1/engines/{ENGINE_NAME}/analytics/clicks
// An example JSON payload from the analytics/counts endpoint.
{
  "results": [
    {
      "clicks": number,
      "queries": number,
      "from": date,
      "to": date
    }
  ]
}

Weekly Counts

Return 7 days worth of results by default.

Each object represents a single day.

Example - A GET request with no addition parameters.

curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/analytics/counts' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxxxxxxxxxxxxxxxx'

Example Response

{
  "results": [
    {
      "clicks": 123,
      "queries": 2322,
      "from": "2018-07-02T10:24:46Z",
      "to": "2018-07-03T00:00:00+00:00"
    },
    {
      "clicks": 214,
      "queries": 5122,
      "from": "2018-07-03T00:00:00+00:00",
      "to": "2018-07-04T00:00:00+00:00"
    },
    {
      "clicks": 321,
      "queries": 4544,
      "from": "2018-07-04T00:00:00+00:00",
      "to": "2018-07-05T00:00:00+00:00"
    },
    {
      "clicks": 10,
      "queries": 500,
      "from": "2018-07-05T00:00:00+00:00",
      "to": "2018-07-06T00:00:00+00:00"
    },
    {
      "clicks": 434,
      "queries": 1100,
      "from": "2018-07-06T00:00:00+00:00",
      "to": "2018-07-07T00:00:00+00:00"
    },
    {
      "clicks": 312,
      "queries": 4343,
      "from": "2018-07-07T00:00:00+00:00",
      "to": "2018-07-08T00:00:00+00:00"
    },
    {
      "clicks": 87,
      "queries": 434,
      "from": "2018-07-08T00:00:00+00:00",
      "to": "2018-07-09T00:00:00+00:00"
    },
    {
      "clicks": 23,
      "queries": 439,
      "from": "2018-07-09T00:00:00+00:00",
      "to": "2018-07-09T10:24:46Z"
    }
  ]
}

Counts Filtering

filters (optional)
The filters key is the parent key. If no options are provided underneath it, the last 7 days are returned.
query (optional)
You can supply a particular query to see the relevant documents that have received clicks and/or queries within a time frame. You may only include one query parameter. View example.
tag (optional)
The Search endpoint can be used to attach tags to your documents. One or more tags can be applied to filter results via the API or within your analytics dashboard. View example.
document_id (optional)
Providing a document_id will narrow results down to that specific document. You may only provide one document_id at a time. View example.
date (optional)
Specify a range of time. The from and to fields are optional and the expected format is RFC3339. You may omit the time: YYYY-MM-DD. View example.
interval (optional)
You can define an interval along with your date range. Can be either hour or day, with day as the default. You are limited to a maximum of 100 results within your interval. Therefore, when expecting hours, a date range can not exceed 100 hours or 4 days.
all (optional)
Nest multiple filters under the all option. View example.

Query

Example - A GET request with the query filter option. We want to see how many clicks and queries the everglade query received over the default 7 day time period.

curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/analytics/counts' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxxxxxxxxxxxxxxxx' \
-d '{
  "filters": { "query": "everglade" }
}'

Example Response

{
  "results": [
    {
      "clicks": 23,
      "queries": 322,
      "from": "2018-07-02T10:24:46Z",
      "to": "2018-07-03T00:00:00+00:00"
    },
    {
      "clicks": 14,
      "queries": 122,
      "from": "2018-07-03T00:00:00+00:00",
      "to": "2018-07-04T00:00:00+00:00"
    },
    {
      "clicks": 21,
      "queries": 544,
      "from": "2018-07-04T00:00:00+00:00",
      "to": "2018-07-05T00:00:00+00:00"
    },
    {
      "clicks": 1,
      "queries": 50,
      "from": "2018-07-05T00:00:00+00:00",
      "to": "2018-07-06T00:00:00+00:00"
    },
    {
      "clicks": 34,
      "queries": 100,
      "from": "2018-07-06T00:00:00+00:00",
      "to": "2018-07-07T00:00:00+00:00"
    },
    {
      "clicks": 12,
      "queries": 343,
      "from": "2018-07-07T00:00:00+00:00",
      "to": "2018-07-08T00:00:00+00:00"
    },
    {
      "clicks": 7,
      "queries": 34,
      "from": "2018-07-08T00:00:00+00:00",
      "to": "2018-07-09T00:00:00+00:00"
    },
    {
      "clicks": 3,
      "queries": 39,
      "from": "2018-07-09T00:00:00+00:00",
      "to": "2018-07-09T10:24:46Z"
    }
  ]
}

Tag(s)

We have a Tags Guide, too.

Single Tag

Example - A GET request with the tag filter option. We want to see how many clicks and queries that documents with the web tag received over the default 7 day time period.

curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/analytics/counts' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxxxxxxxxxxxxxxxx' \
-d '{
  "filters": { "tag": "web" }
}'

Example Response

{
  "results": [
    {
      "clicks": 1,
      "queries": 12,
      "from": "2018-07-02T10:24:46Z",
      "to": "2018-07-03T00:00:00+00:00"
    },
    {
      "clicks": 2,
      "queries": 44,
      "from": "2018-07-03T00:00:00+00:00",
      "to": "2018-07-04T00:00:00+00:00"
    },
    {
      "clicks": 1,
      "queries": 133,
      "from": "2018-07-04T00:00:00+00:00",
      "to": "2018-07-05T00:00:00+00:00"
    },
    {
      "clicks": 5,
      "queries": 234,
      "from": "2018-07-05T00:00:00+00:00",
      "to": "2018-07-06T00:00:00+00:00"
    },
    {
      "clicks": 4,
      "queries": 211,
      "from": "2018-07-06T00:00:00+00:00",
      "to": "2018-07-07T00:00:00+00:00"
    },
    {
      "clicks": 2,
      "queries": 146,
      "from": "2018-07-07T00:00:00+00:00",
      "to": "2018-07-08T00:00:00+00:00"
    },
    {
      "clicks": 2,
      "queries": 245,
      "from": "2018-07-08T00:00:00+00:00",
      "to": "2018-07-09T00:00:00+00:00"
    },
    {
      "clicks": 2,
      "queries": 210,
      "from": "2018-07-09T00:00:00+00:00",
      "to": "2018-07-09T10:24:46Z"
    }
  ]
}
Multiple Tags

Example - A GET request with the tag filter option containing multiple tags. We want to see how many clicks and queries that documents with the web and mobile tags received over the default 7 day time period.

curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/analytics/counts' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxxxxxxxxxxxxxxxx' \
-d '{
  "filters": { "tag": ["web", "mobile"] }
}'

Example Response

{
  "results": [
    {
      "clicks": 2,
      "queries": 22,
      "from": "2018-07-02T10:24:46Z",
      "to": "2018-07-03T00:00:00+00:00"
    },
    {
      "clicks": 4,
      "queries": 34,
      "from": "2018-07-03T00:00:00+00:00",
      "to": "2018-07-04T00:00:00+00:00"
    },
    {
      "clicks": 3,
      "queries": 233,
      "from": "2018-07-04T00:00:00+00:00",
      "to": "2018-07-05T00:00:00+00:00"
    },
    {
      "clicks": 1,
      "queries": 450,
      "from": "2018-07-05T00:00:00+00:00",
      "to": "2018-07-06T00:00:00+00:00"
    },
    {
      "clicks": 11,
      "queries": 1403,
      "from": "2018-07-06T00:00:00+00:00",
      "to": "2018-07-07T00:00:00+00:00"
    },
    {
      "clicks": 5,
      "queries": 546,
      "from": "2018-07-07T00:00:00+00:00",
      "to": "2018-07-08T00:00:00+00:00"
    },
    {
      "clicks": 2,
      "queries": 375,
      "from": "2018-07-08T00:00:00+00:00",
      "to": "2018-07-09T00:00:00+00:00"
    },
    {
      "clicks": 2,
      "queries": 240,
      "from": "2018-07-09T00:00:00+00:00",
      "to": "2018-07-09T10:24:46Z"
    }
  ]
}

Document ID

Example - A GET request with the document_id filter option. We want to see how many clicks and queries that the document with id 321 received over the default 7 day time period.

curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/analytics/counts' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxxxxxxxxxxxxxxxx' \
-d '{
  "filters": { "document_id": 321 }
}'

Example Response

{
  "results": [
    {
      "clicks": 4,
      "queries": 239,
      "from": "2018-07-02T10:24:46Z",
      "to": "2018-07-03T00:00:00+00:00"
    },
    {
      "clicks": 1,
      "queries": 131,
      "from": "2018-07-03T00:00:00+00:00",
      "to": "2018-07-04T00:00:00+00:00"
    },
    {
      "clicks": 3,
      "queries": 356,
      "from": "2018-07-04T00:00:00+00:00",
      "to": "2018-07-05T00:00:00+00:00"
    },
    {
      "clicks": 1,
      "queries": 150,
      "from": "2018-07-05T00:00:00+00:00",
      "to": "2018-07-06T00:00:00+00:00"
    },
    {
      "clicks": 6,
      "queries": 190,
      "from": "2018-07-06T00:00:00+00:00",
      "to": "2018-07-07T00:00:00+00:00"
    },
    {
      "clicks": 3,
      "queries": 411,
      "from": "2018-07-07T00:00:00+00:00",
      "to": "2018-07-08T00:00:00+00:00"
    },
    {
      "clicks": 1,
      "queries": 34,
      "from": "2018-07-08T00:00:00+00:00",
      "to": "2018-07-09T00:00:00+00:00"
    },
    {
      "clicks": 6,
      "queries": 339,
      "from": "2018-07-09T00:00:00+00:00",
      "to": "2018-07-09T10:24:46Z"
    }
  ]
}

Date

Example - A POST request with the date filters option. We want a shorter time frame than the default 7 days. We only want 4 days. Expects results from the earlier date, to the later date.

curl -X POST 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/analytics/counts' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxxxxxxxxxxxxxxxx' \
-d '{
  "filters": {
    "date": {
      "from": "2018-06-15T00:00:00+00:00",
      "to": "2018-06-19T00:00:00+00:00"
    }
  }
}'

Example Response

{
  "results": [
    {
      "clicks": 1,
      "queries": 139,
      "from": "2018-06-15T00:00:00+00:00",
      "to": "2018-07-16T00:00:00+00:00"
    },
    {
      "clicks": 3,
      "queries": 349,
      "from": "2018-07-16T00:00:00+00:00",
      "to": "2018-07-17T00:00:00+00:00"
    },
    {
      "clicks": 2,
      "queries": 297,
      "from": "2018-07-17T00:00:00+00:00",
      "to": "2018-07-18T00:00:00+00:00"
    },
    {
      "clicks": 1,
      "queries": 111,
      "from": "2018-07-18T00:00:00+00:00",
      "to": "2018-07-19T00:00:00+00:00"
    }
  ]
}

Interval

Only 100 results may be returned at one time. Changing the interval will require a date range set to no greater than 100 hours or 4 days.

Example - A POST request with the date filters option. We are asking for a 6 hour window. Interval is set to hour.

curl -X POST 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/analytics/counts' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxxxxxxxxxxxxxxxx' \
-d '{
  "filters": {
    "date": {
      "from": "2018-06-18T18:00:00+00:00",
      "to": "2018-06-19T00:00:00+00:00"
    }
  },
  "interval": "hour"
}'

Example Response

{
  "results": [
    {
      "clicks": 0,
      "queries": 31,
      "from": "2018-06-18T18:00:00+00:00",
      "to": "2018-06-18T19:00:00+00:00"
    },
    {
      "clicks": 0,
      "queries": 58,
      "from": "2018-06-18T19:00:00+00:00",
      "to": "2018-06-18T20:00:00+00:00"
    },
    {
      "clicks": 0,
      "queries": 24,
      "from": "2018-06-18T20:00:00+00:00",
      "to": "2018-06-18T21:00:00+00:00"
    },
    {
      "clicks": 0,
      "queries": 34,
      "from": "2018-06-18T21:00:00+00:00",
      "to": "2018-06-18T22:00:00+00:00"
    },
    {
      "clicks": 0,
      "queries": 15,
      "from": "2018-06-18T22:00:00+00:00",
      "to": "2018-06-18T23:00:00+00:00"
    },
    {
      "clicks": 0,
      "queries": 9,
      "from": "2018-06-18T23:00:00+00:00",
      "to": "2018-06-19T00:00:00+00:00"
    }
  ]
}

Multiple Filters

Example - A GET request with the date and tag filter options. We want to see how many clicks and queries documents with the web and mobile tag received within a 2 day window.

curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/analytics/counts' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxxxxxxxxxxxxxxxx' \
-d '{
  "filters": {
    "all": [
      {
        "date": {
          "from": "2018-06-17T00:00:00+00:00",
          "to": "2018-06-19T00:00:00+00:00"
        }
      }, {
        "tag": ["web", "mobile"]
      }
    ]
  }'

Example Response

{
  "results": [
    {
      "clicks": 4,
      "queries": 639,
      "from": "2018-06-15T00:00:00+00:00",
      "to": "2018-07-16T00:00:00+00:00"
    },
    {
      "clicks": 13,
      "queries": 949,
      "from": "2018-07-16T00:00:00+00:00",
      "to": "2018-07-17T00:00:00+00:00"
    }
  ]
}

Full Example

You can combine all of the different parameters for granular responses.

Including both tags and document_id is strange, but it helps to see everything within one example.

Example - A GET request that includes the interval and filters arguments. All filters options are included. The interval is set to hour, with the date range set to 2 hours.

curl -X GET 'https://host-2376rb.api.swiftype.com/api/as/v1/engines/national-parks-demo/analytics/clicks' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxxxxxxxxxxxxxxxx' \
-d '{
  "filters": {
    "all": [
      {
        "tag": ["mobile", "web"]
      },{
        "query": "rails"
      }, {
        "document_id": "163"
      }, {
        "date": {
          "from": "2018-07-05T12:00:00+00:00",
          "to": "2018-07-05T14:00:00+00:00"
        }
      }
    ]
  },
  "interval": "hour"
}'

Example Response

{
  "results": [
    {
      "clicks": 1,
      "queries": 139,
      "from": "2018-07-05T12:00:00+00:00",
      "to": "2018-07-05T13:00:00+00:00"
    },
    {
      "clicks": 0,
      "queries": 59,
      "from": "2018-07-05T13:00:00+00:00",
      "to": "2018-07-05T14:00:00+00:00"
    }
  ]
}