-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding User Behavior Insights functionality. #13546
Closed
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# User Behavior Insights (UBI) | ||
|
||
UBI facilitates storing queries and events for the purposes of improving search relevance as descrbed by [[RFC] User Behavior Insights](https://github.com/opensearch-project/OpenSearch/issues/12084). | ||
|
||
## Indexing Queries | ||
|
||
For UBI to index a query, add a `ubi` block to the `ext` in the search request containing a `query_id`: | ||
|
||
``` | ||
curl -s http://localhost:9200/ecommerce/_search -H "Content-type: application/json" -d' | ||
{ | ||
"query": { | ||
"match": { | ||
"title": "toner OR ink" | ||
} | ||
}, | ||
"ext": { | ||
"ubi": { | ||
"query_id": "1234512345" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
There are optional values that can be included in the `ubi` block along with the `query_id`. Those values are: | ||
* `client_id` - A unique identifier for the source of the query. This may represent a user or some other mechanism. | ||
* `user_query` - The user-entered query for this search. For example, in the search request above, the `user_query` may have been `toner ink`. | ||
|
||
With these optional values, a sample query would look like: | ||
|
||
``` | ||
curl -s http://localhost:9200/ecommerce/_search -H "Content-type: application/json" -d' | ||
{ | ||
"query": { | ||
"match": { | ||
"title": "toner OR ink" | ||
} | ||
}, | ||
"ext": { | ||
"ubi": { | ||
"query_id": "1234512345", | ||
"client_id": "abcdefg", | ||
"user_query": "toner ink" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
If a search request does not contain a `ubi` block in `ext`, the query will *not* be indexed. | ||
|
||
Queries are indexed into an index called `ubi_queries`. | ||
|
||
## Indexing Events | ||
|
||
UBI facilitates indexing both queries and client-side events. These client-side events may be product clicks, scroll-depth, | ||
adding a product to a cart, or other actions. UBI indexes these events in an index called `ubi_events`. This index is | ||
automatically created the first time a query containing a `ubi` section in `ext` (example above). | ||
|
||
Client-side events can be indexed into the `ubi_events` index by your method of choice. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apply plugin: 'opensearch.yaml-rest-test' | ||
|
||
opensearchplugin { | ||
description 'Integrates OpenSearch with systemd' | ||
classname 'org.opensearch.ubi.UbiModulePlugin' | ||
} | ||
|
||
dependencies { | ||
// required for the yaml test to run | ||
yamlRestTestImplementation "org.apache.logging.log4j:log4j-core:${versions.log4j}" | ||
runtimeOnly "org.apache.logging.log4j:log4j-core:${versions.log4j}" | ||
} |
77 changes: 77 additions & 0 deletions
77
modules/ubi/src/main/java/org/opensearch/ubi/QueryRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.ubi; | ||
|
||
/** | ||
* A query received by OpenSearch. | ||
*/ | ||
public class QueryRequest { | ||
|
||
private final long timestamp; | ||
private final String queryId; | ||
private final String userId; | ||
private final String userQuery; | ||
private final QueryResponse queryResponse; | ||
|
||
/** | ||
* Creates a query request. | ||
* @param queryId The ID of the query. | ||
* @param userQuery The user-entered query. | ||
* @param userId The ID of the user that initiated the query. | ||
* @param queryResponse The {@link QueryResponse} for this query request. | ||
*/ | ||
public QueryRequest(final String queryId, final String userQuery, final String userId, final QueryResponse queryResponse) { | ||
this.timestamp = System.currentTimeMillis(); | ||
this.queryId = queryId; | ||
this.userId = userId; | ||
this.userQuery = userQuery; | ||
this.queryResponse = queryResponse; | ||
} | ||
|
||
/** | ||
* Gets the timestamp. | ||
* @return The timestamp. | ||
*/ | ||
public long getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
/** | ||
* Gets the query ID. | ||
* @return The query ID. | ||
*/ | ||
public String getQueryId() { | ||
return queryId; | ||
} | ||
|
||
/** | ||
* Gets the user query. | ||
* @return The user query. | ||
*/ | ||
public String getUserQuery() { | ||
return userQuery; | ||
} | ||
|
||
/** | ||
* Gets the user ID. | ||
* @return The user ID. | ||
*/ | ||
public String getUserId() { | ||
return userId; | ||
} | ||
|
||
/** | ||
* Gets the query response for this query request. | ||
* @return The {@link QueryResponse} for this query request. | ||
*/ | ||
public QueryResponse getQueryResponse() { | ||
return queryResponse; | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
modules/ubi/src/main/java/org/opensearch/ubi/QueryResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.ubi; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* A query response. | ||
*/ | ||
public class QueryResponse { | ||
|
||
private final String queryId; | ||
private final String queryResponseId; | ||
private final List<String> queryResponseObjectIds; | ||
|
||
/** | ||
* Creates a query response. | ||
* @param queryId The ID of the query. | ||
* @param queryResponseId The ID of the query response. | ||
* @param queryResponseObjectIds A list of IDs for the hits in the query. | ||
*/ | ||
public QueryResponse(final String queryId, final String queryResponseId, final List<String> queryResponseObjectIds) { | ||
this.queryId = queryId; | ||
this.queryResponseId = queryResponseId; | ||
this.queryResponseObjectIds = queryResponseObjectIds; | ||
} | ||
|
||
/** | ||
* Gets the query ID. | ||
* @return The query ID. | ||
*/ | ||
public String getQueryId() { | ||
return queryId; | ||
} | ||
|
||
/** | ||
* Gets the query response ID. | ||
* @return The query response ID. | ||
*/ | ||
public String getQueryResponseId() { | ||
return queryResponseId; | ||
} | ||
|
||
/** | ||
* Gets the list of query response hit IDs. | ||
* @return A list of query response hit IDs. | ||
*/ | ||
public List<String> getQueryResponseObjectIds() { | ||
return queryResponseObjectIds; | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like if you do not have a
query_id
, one will be provided for you.Is the presence of an empty
ubi
block sufficient to get the logging?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had it generate a
query_id
if none is provided but I should not have yet. In this first version, aquery_id
is required. This is because the search response is not yet being modified. In a later revision,query_id
will be optional and generated if not provided and returned in the search response'sext
. I will remove that code ingetQueryId()
to make a random UUID if it'snull
.An empty block was sufficient, but I will change it to require that the
ubi
block contains aquery_id
. If noubi
block, or an emptyubi
block, the rest of the code in theUbiActionFilter
will be skipped.