Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Documentation/query examples #110

Merged
merged 9 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ services:
http.cors.allow-origin: "*"
http.cors.allow-methods: OPTIONS,TRACE,HEAD,GET,POST,PUT,DELETE
http.cors.allow-credentials: true
http.cors.allow-headers: X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
http.cors.allow-headers: X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization,X-ubi-store,X-ubi-query-id,X-ubi-user-id,X-ubi-session-id
plugins.ubi.indices: "awesome"
logger.level: info
OPENSEARCH_INITIAL_ADMIN_PASSWORD: SuperSecretPassword_123
ulimits:
Expand Down
28 changes: 17 additions & 11 deletions documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ index is used to store events, and the other index is for storing queries.
Schema for events:

**Primary fields include:**
- `action_name` - any name you want to call your event
- `action_name` - (size 100)- any name you want to call your event
- `timestamp` - should be set automatically
- `user_id`. `session_id`, `page_id` - are id's largely at the calling client's discretion for tracking users, sessions and pages
- `query_id` - ID for some query. Note that it could be a unique search string, or it could represent a cluster of related searches (i.e.: *dress*, *red dress*, *long dress* could all have the same `query_id`). Either the client could control these, or the `query_id` could be retrieved from the API's response headers as it keeps track of queries on the node
- `message_type` - originally thought of in terms of ERROR, INFO, WARN...but could be anything useful such as `QUERY` or `PURCHASE`
- `message` - optional text for the log entry
- `user_id`. `session_id`, `page_id` - (size 100) - are id's largely at the calling client's discretion for tracking users, sessions and pages
- `query_id` - (size 100) - ID for some query. Note that it could be a unique search string, or it could represent a cluster of related searches (i.e.: *dress*, *red dress*, *long dress* could all have the same `query_id`). Either the client could control these, or the `query_id` could be retrieved from the API's response headers as it keeps track of queries on the node
- `message_type` - (size 100) - originally thought of in terms of ERROR, INFO, WARN...but could be anything useful such as `QUERY` or `PURCHASE`
- `message` - (size 256) - optional text for the log entry

**Other fields & data objects**
- `event_attributes` - contains various, common attributes associated with many user events
Expand All @@ -38,6 +38,10 @@ Schema for events:
- `event_attributes.data.transaction_id` - optionally points to a unique id representing a successful transaction
- `event_attributes.data.to_user_id` - optionally points to another user, if they are the recipient of this object
- `event_attributes.data.data_detail` - optional data object/map of further data details
-
*Other mapped fields in the schema are intended to be optional placeholders for common attributes like `city`, `state`, `price`

**the users can dynamically add any further fields to the event mapping

## Plugin API

Expand Down Expand Up @@ -98,12 +102,12 @@ To make this association, queries need to have a header value that indicates the

#### Required Headers

|Header|Purpose|Required?|
|---|---|---|
|`X-ubi-store`|Tells the plugin which store this query should be persisted to.|Required|
|`X-ubi-user-id`|Allow for associating client-side user events with the query|Required|
|`X-ubi-query-id`|The client can provide a query ID. If not provided, the plugin will generate a random query ID. The purpose of the query ID is to uniquely identify the query.|No|
|`X-ubi-session-id`|A session ID to associate with the query.|No|
|Header|Purpose|Required?|Detail|
|---|---|---|---|
|`X-ubi-store`|Tells the plugin which store this query should be persisted to.|Required||
|`X-ubi-user-id`|Allow for associating client-side user events with the query|Required||
|`X-ubi-query-id`|The client can provide a query ID. If not provided, the plugin will generate a random query ID. The purpose of the query ID is to uniquely identify the query.|No|[query_id](./query_id.md)|
|`X-ubi-session-id`|A session ID to associate with the query.|No||

### Example Queries

Expand All @@ -114,3 +118,5 @@ curl http://localhost:9200/ecommerce/_search -H "X-ubi-store: mystore" -H "X-ubi
```

With this query, when the plugin sees a query, the plugin will be able to associate the query with an individual user and know to persist the query in the UBI store `mystore`.

[Sample SQL queries](getting-started\queries\sql_queries.md)
81 changes: 81 additions & 0 deletions getting-started/queries/dsl_queries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@


```json
GET .ubi_log_events/_search
{
"size":0,
"aggs":{
"event_types":{
"terms": {
"field":"action_name",
"size":10
}
}
}
}
```
returns
```json
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 10000,
"relation": "gte"
},
"max_score": null,
"hits": []
},
"aggregations": {
"event_types": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "brand_filter",
"doc_count": 3084
},
{
"key": "product_hover",
"doc_count": 3068
},
{
"key": "button_click",
"doc_count": 3054
},
{
"key": "product_sort",
"doc_count": 3012
},
{
"key": "on_search",
"doc_count": 3010
},
{
"key": "type_filter",
"doc_count": 2925
},
{
"key": "login",
"doc_count": 2433
},
{
"key": "logout",
"doc_count": 1447
},
{
"key": "new_user_entry",
"doc_count": 207
}
]
}
}
}
```
Loading
Loading