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

Commit

Permalink
Changing id_field to key_field.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzonthemtn committed Mar 30, 2024
1 parent 87250c5 commit 4b0ddcd
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions documentation/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ docker compose -f docker-compose-cluster.yaml up
Initialize the `awesome` UBI store:

```
curl -X PUT "http://localhost:9200/_plugins/ubi/awesome?index=ecommerce&id_field=id"
curl -X PUT "http://localhost:9200/_plugins/ubi/awesome?index=ecommerce&key_field=id"
```

Send an event to the `awesome` store:
Expand Down Expand Up @@ -88,7 +88,7 @@ The current event mappings file can be found [here](https://github.com/o19s/open
- `event_attributes.object` - contains an associated JSONified data object (i.e. books, products, user info, etc) if there are any
- `event_attributes.object.object_id` - points to a unique, internal, id representing and instance of that object
- `event_attributes.object.key_value` - points to a unique, external key, matching the item that the user searched for, found and acted upon (i.e. sku, isbn, ean, etc.).
**This field value should match the value in for the object's value in the `id_field` [below](#id_field) from the search store**
**This field value should match the value in for the object's value in the `key_field` [below](#key_field) from the search store**
It is possible that the `object_id` and `key_value` match if the same id is used both internally for indexing and externally for the users.
- `event_attributes.object.object_type` - indicates the type/class of object
- `event_attributes.object.description` - optional description of the object
Expand Down Expand Up @@ -122,7 +122,7 @@ The plugin exposes a REST API for managing UBI stores and persisting events.

| Method | Endpoint | Purpose |
|--------|-----------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `PUT` | `/_plugins/ubi/{store}?index={index}&id_field={id_field}` | <p id="id_field">Initialize a new UBI store for the given index. The `id_field` is optional and allows for providing the name of a field in the `index`'s schema to be used as the unique result/item ID for each search result. If not provided, the `_id` field is used. </p>|
| `PUT` | `/_plugins/ubi/{store}?index={index}&key_field={key_field}` | <p id="key_field">Initialize a new UBI store for the given index. The `key_field` is optional and allows for providing the name of a field in the `index`'s schema to be used as the unique result/item ID for each search result. If not provided, the `_id` field is used. </p>|
| `DELETE` | `/_plugins/ubi/{store}` | Delete a UBI store |
| `GET` | `/_plugins/ubi` | Get a list of all UBI stores |
| `POST` | `/_plugins/ubi/{store}` | Index an event into the UBI store |
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/o19s/ubi/UserBehaviorInsightsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public List<Setting<?>> getSettings() {

settings.add(Setting.intSetting(SettingsConstants.VERSION_SETTING, 1, -1, Integer.MAX_VALUE, Setting.Property.IndexScope));
settings.add(Setting.simpleString(SettingsConstants.INDEX, "", Setting.Property.IndexScope));
settings.add(Setting.simpleString(SettingsConstants.ID_FIELD, "", Setting.Property.IndexScope));
settings.add(Setting.simpleString(SettingsConstants.KEY_FIELD, "", Setting.Property.IndexScope));

return settings;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ public void onResponse(Response response) {
if(!"".equals(storeName)) {

final String index = getStoreSettings(storeName, SettingsConstants.INDEX);
final String idField = getStoreSettings(storeName, SettingsConstants.ID_FIELD);
final String idField = getStoreSettings(storeName, SettingsConstants.KEY_FIELD);

LOGGER.debug("Using id_field [{}] of index [{}] for UBI query.", idField, index);
LOGGER.debug("Using key_field [{}] of index [{}] for UBI query.", idField, index);

// Only consider this search if the index being searched matches the store's index setting.
if (Arrays.asList(searchRequest.indices()).contains(index)) {
Expand All @@ -124,7 +124,7 @@ public void onResponse(Response response) {

if (idField == null || "".equals(idField) || idField.equals("null")) {

// Use the _id since there is no id_field setting for this index.
// Use the _id since there is no key_field setting for this index.
queryResponseHitIds.add(String.valueOf(hit.docId()));

} else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/o19s/ubi/model/SettingsConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public class SettingsConstants {
/**
* The field in an index's mapping that will be used as the unique identifier for a query result item.
*/
public static final String ID_FIELD = "index.ubi.id_field";
public static final String KEY_FIELD = "index.ubi.key_field";

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient

final String storeName = restRequest.param("store");
final String index = restRequest.param("index");
final String idField = restRequest.param("id_field");
final String idField = restRequest.param("key_field");

LOGGER.info("Received PUT for store {}", storeName);

Expand Down Expand Up @@ -191,7 +191,7 @@ private RestChannelConsumer create(final NodeClient nodeClient, final String sto
.put(IndexMetadata.INDEX_AUTO_EXPAND_REPLICAS_SETTING.getKey(), "0-2")
.put(IndexMetadata.SETTING_PRIORITY, Integer.MAX_VALUE)
.put(SettingsConstants.INDEX, index)
.put(SettingsConstants.ID_FIELD, idField)
.put(SettingsConstants.KEY_FIELD, idField)
.put(SettingsConstants.VERSION_SETTING, VERSION)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"type": "string",
"description": "The name of the index being searched"
},
"id_field": {
"key_field": {
"required": false,
"type": "string",
"description": "The name of the field to use for the doc ID field"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
ubi.create_store:
store: mystore
index: ecommerce
id_field: name
key_field: name

- do:
cluster.health:
Expand Down Expand Up @@ -60,14 +60,14 @@
index: ""

---
"Create a store without specifying an id_field":
# A missing id_field is allowed - the doc ID will be used instead.
"Create a store without specifying an key_field":
# A missing key_field is allowed - the doc ID will be used instead.

- do:
ubi.create_store:
store: invalid_store
index: some_index
id_field: ""
key_field: ""

---
"Delete a store that does not exist":
Expand All @@ -86,7 +86,7 @@
ubi.create_store:
store: mystore
index: ecommerce
id_field: name
key_field: name

- do:
cluster.health:
Expand All @@ -97,6 +97,6 @@
ubi.create_store:
store: mystore
index: ecommerce
id_field: name
key_field: name

- match: { status: initialized }

0 comments on commit 4b0ddcd

Please sign in to comment.