iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 28
1
Elastic Stack on Cloud

少女人妻的30天Elastic系列 第 28

【少女人妻的30天Elastic】Day 28 : App Search_API 介紹與應用_Analytics

Aloha!又是我少女人妻 Uerica!鐵人賽終於快結束拉,沒想到默默的堅持到快要終點了,我家狗狗最近訓練一身絕技,以前都站起來拍我肩膀或手臂,現在都直接拍掉我滑鼠哈哈哈


Analytics API

用來分析查詢行為與點擊次數有關的 API

Queries : 一個時間範圍內的被查詢和點擊次數。
Clicks : 字詞的點擊次數。
Counts : 一天的查詢與點擊總數。

Queries

依降幕返回一定時間內的查詢和點擊次數

GET /api/as/v1/engines/{ENGINE_NAME}/analytics/queries
POST /api/as/v1/engines/{ENGINE_NAME}/analytics/queries

Top Queries

  • page/size (optional) : 顯示回傳資料的頁數與筆數

利用 GET 獲取過去七天前十名的熱門查詢與次數, body 不帶任何參數

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/queries' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d ''

Pagination

指定回傳資料的結果筆數

指定回傳 20 筆

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/queries' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d '{
  "page": {
    "size": 20
  }
}'

Queries Filtering

  • filters (optional) : filters key 是 parent key,如果沒有提供任何選項,預設回傳七天內前十筆熱門的查詢資料
  • clicks (optional) : 指定回傳資料是否帶有 clicks 資訊,希望帶有 clicks 資訊為 true
  • results (optional) : 指定回傳資料是否帶有 results 資訊,希望帶有 results 資訊為 true
  • tag (optional) : 為搜尋行為加上 tag 可供分析
  • date (optional) : 回傳指定時間範圍內的查詢。 from 和 to 可選填,預期格式為 RFC3339 。您可以省略時間:YYYY-MM-DD。
  • all (optional) : 在 all 選項下嵌套多個過濾條件

指定回傳資料帶有 clicks 資訊

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/queries' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d '{
  "filters": { "clicks": true }
}'

指定回傳資料不帶有 results 資訊

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/queries' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d '{
  "filters": { "results": false }
}'

指定查詢帶有 single tag

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/queries' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d '{
  "filters": { "tag": "web" }
}'

指定查詢帶有 multiple tags

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/queries' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d '{
  "filters": { "tag": ["web", "mobile"] }
}'

用 POST 指定查詢一定時間範圍的結果

curl -X POST '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/queries' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d '{
  "filters": {
    "date": {
      "from": "2018-06-15T12:00:00+00:00",
      "to": "2018-06-19T00:00:00+00:00"
    }
  }
}'

多個過濾條件

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/queries' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d '{
  "filters": {
    "all": [
      {
        "clicks": false
      }, {
        "results": true
      }
    ]
  }
}'

Full Example

完整過濾條件示範

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/queries' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d '{
  "filters": {
    "all": [
      {
        "clicks": false
      }, {
        "date": {
          "from": "2018-06-15T12:00:00+00:00",
          "to": "2018-06-19T00:00:00+00:00"
        }
      }, {
        "results": false
      }, {
        "tag": ["web", "mobile"]
      }
    ]
  },
  "page": {
    "size": 20
  }
}'

Clicks

依降幕回傳一定時間內的點擊次數

GET /api/as/v1/engines/{ENGINE_NAME}/analytics/clicks
POST /api/as/v1/engines/{ENGINE_NAME}/analytics/clicks

Top Clicks

  • page/size (optional) : 顯示回傳資料的頁數與筆數

利用 GET 獲取過去七天前十名的熱門點擊次數, body 不帶任何參數

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/clicks' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d ''

Pagination

指定回傳資料的結果筆數

指定回傳 20 筆

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/clicks' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d '{
  "page": {
    "size": 20
  }
}'

By Query

查看特定字詞的點擊次數

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/clicks' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d '{
  "query": "花蓮"
}'

Clicks Filtering

  • filters (required) : filters key 是 parent key,如果沒有提供任何選項,預設回傳七天內前十筆熱門點擊資料
  • tag (optional) : 為搜尋行為加上 tag 可供分析
  • date (optional) : 回傳指定時間範圍內的查詢。 from 和 to 可選填,預期格式為 RFC3339 。您可以省略時間:YYYY-MM-DD。
  • all (optional) : 在 all 選項下嵌套多個過濾條件

查看特定時間內的最高點擊資料

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/clicks' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d '{
  "filters": {
    "date": {
      "from": "2018-06-15T12:00:00+00:00",
      "to": "2018-06-19T00:00:00+00:00"
    }
  }
}'

為查詢帶入 single tag

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/clicks' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d '{
  "filters": { "tag": "web" }
}'

為查詢帶入 multiple tag

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/clicks' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d '{
  "filters": { "tag": ["web", "mobile"] }
}'

多個過濾條件

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/clicks' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d '{
  "filters": {
    "all": [
      {
        "clicks": false
      }, {
        "results": true
      }
    ]
  }
}'

Full Example

完整過濾條件示範

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/clicks' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d '{
  "filters": {
    "all": [
      {
        "clicks": false
      }, {
        "date": {
          "from": "2018-06-15T12:00:00+00:00",
          "to": "2018-06-19T00:00:00+00:00"
        }
      }, {
        "results": false
      }, {
        "tag": ["web", "mobile"]
      }
    ]
  },
  "page": {
    "size": 20
  }
}'

Count

以升幕方式回傳一天的總點擊數量和總查詢數。默認時間/日期格式是RFC3339。

GET /api/as/v1/engines/{ENGINE_NAME}/analytics/counts
POST /api/as/v1/engines/{ENGINE_NAME}/analytics/counts

Weekly Counts

回傳七天的總查詢與總點擊結果,一筆為一天的統計

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/counts' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-d ''

完整過濾條件示範

curl -X GET '{API_Endpoint}/api/as/v1/engines/{ENGINE_NAME}/analytics/counts' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-xxxxxxxxxx' \
-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"
}'  

再次感謝大家閱讀,今天就先到這邊摟!明天見掰掰~


上一篇
【少女人妻的30天Elastic】Day 27 : App Search_API 介紹與應用_Search Settings
下一篇
【少女人妻的30天Elastic】Day 29 : App Search_API 介紹與應用_Curations
系列文
少女人妻的30天Elastic30

尚未有邦友留言

立即登入留言