forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opensearch-project#13545 Adding User Behavior Insights functionality.
Signed-off-by: jzonthemtn <[email protected]>
- Loading branch information
1 parent
9106713
commit bea92e0
Showing
19 changed files
with
1,552 additions
and
0 deletions.
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. | ||
|
||
## 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.