HungryHub Kafka Search Events Documentation
This document provides detailed information about the schema for the events that are sent to Kafka for the search service in HungryHub. It covers the different types of events, their payloads, and provides examples of each.
Please let us know if you have any questions or suggestions.
Table of Contents
- HungryHub Kafka Search Events Documentation
- Table of Contents
- Restaurant Events
- Restaurant Tags Events
- Restaurant Tag Groups Events
Event Operations
The events can have the following operations:
| Operation | Description |
|---|---|
| index | Full reindex the documents with the new data |
| create | Add new documents to the index |
| update | Update documents in the index |
| delete | Delete documents from the index |
Event Payload
The payload of the event is a JSON object with the following fields:
| Field | Type | Description |
|---|---|---|
| op | String | The type of the event (index, create, update, delete) |
| batch_number | Integer | The batch number of the event. The batch number starts from 0. |
| total_items | Integer | The total number of all items to be indexed (sum of all batches). |
| job_id | String | The Sidekiq job ID (JID) of the job that generated the event. |
| payload | Array, Object | The documents to be indexed, updated or deleted. The structure of the documents is specific to each index. |
Kafka Topics
{namespace}.hh.search.restaurants{namespace}.hh.search.restaurants.availability{namespace}.hh.search.restaurants.tags{namespace}.hh.search.restaurants.tagGroups{namespace}.hh.search.restaurantTags{namespace}.hh.search.restaurantTagGroups
Note: {namespace} is the namespace of the environment
environment name (e.g. ballbot, engineering, venus, staging, production).
| Environment | Namespace | Domain |
|---|---|---|
| Development | localhost | localhost:4000 |
| Ballbot | ballbot | hh-ballbot.my.id |
| Engineering | engineering | hh-engineering.my.id |
| Venus | venus | hh-venus.my.id |
| Staging | staging | hhstaging.dev |
| Production | production | hungryhub.com |
Restaurant Events
Full restaurants reindex or initial index
To perform a full reindex or initial index, you need to send the complete restaurant data. The payload should be an array of documents with a recommended batch size of 5-10 documents per batch (or up to the maximum Kafka message size), and total_items should represent the total number of restaurants.
{
"op": "index",
"batch_number": 0, // batch number starting from 0
"total_items": 100, // total restaurants (send only in the last batch)
"job_id": "ea70569db80ab18ef0f320c7", // sidekiq job id (JID)
"payload": [
/* array of restaurants.json */
]
}
Create new restaurant
To create new documents, use the following format:
Topic: hh.search.restaurants
{
"op": "create",
"payload": {
/* restaurants.json */
}
}
Update restaurant
To update documents, use the following format:
Topic: hh.search.restaurants
{
"op": "update",
"payload": {
/* restaurants.json */
}
}
Replace the availability of a restaurant
To replace the entire availability of a restaurant, use the following format:
Topic: hh.search.restaurants
{
"op": "update",
"payload": {
"id": 34,
"availability": [
{
"date_time": "2024-02-06T12:00",
"adult": 2
}
]
}
}
Full payload: restaurants.json
Delete restaurant
To delete documents, use the following format:
Topic: hh.search.restaurants
{
"op": "delete",
"payload": {
"id": 34
}
}
Update restaurant availability
To update the availability of a restaurant for a specific date time, use the following format:
Topic: hh.search.restaurants.availability
{
"op": "update",
"payload": {
"id": 34,
"availability": [
{
"date_time": "2024-02-06T12:00",
"adult": 2
}
]
}
}
Update restaurants tags
To update the tags of a restaurant, use the following format:
Topic: hh.search.restaurants.tags
{
"op": "update",
"payload": {
"tag": {
"id": 32,
"title_th": "อเมริกัน",
"title_en": "American",
"title_cn": "美国",
"category": "Cuisine",
"synonyms": ["United States", "USA"]
},
"actions": {
"add": [1, 2, 3], // restaurant ids to add
"remove": [4, 5, 6] // restaurant ids to remove
}
}
}
Update restaurants tag groups
To update the tag groups of a restaurant, use the following format:
Topic: hh.search.restaurants.tagGroups
{
"op": "update",
"payload": {
"tag_group": {
"id": 32,
"title_th": "ร้านใกล้รถไฟ",
"title_en": "PLACES NEAR BTS",
"title_cn": "靠近BTS的地方"
},
"actions": {
"add": [1, 2, 3], // retaurant ids to add
"remove": [4, 5, 6] // retaurant ids to remove
}
}
}
Restaurant Tags Events
Full restaurant tags reindex or initial index
To perform a full reindex or initial index, you need to send the complete restaurant tag data. The payload should be an array of documents with a recommended batch size of 20-50 documents per batch (or up to the maximum Kafka message size), and total_items should represent the total number of restaurant tags.
{
"op": "index",
"batch_number": 0, // batch number starting from 0
"total_items": 100, // total restaurant tags (send only in the last batch)
"job_id": "ea70569db80ab18ef0f320c7", // sidekiq job id (JID)
"payload": [
{
"id": 32,
"city_id": null, // null for all cities
"title_th": "อเมริกัน",
"title_en": "American",
"title_cn": "美国",
"category": "Cuisine",
"synonyms": ["United States", "USA"],
"total_restaurants": 100 // total restaurants using this tag
}
/* array of restaurant_tags.json */
]
}
Create new restaurant tag
To create new documents, use the following format:
Topic: hh.search.restaurantTags
{
"op": "create",
"payload": {
"id": 32,
"city_id": null, // null for all cities
"title_th": "อเมริกัน",
"title_en": "American",
"title_cn": "美国",
"category": "Cuisine",
"synonyms": ["United States", "USA"],
"total_restaurants": 100 // total restaurants using this tag
}
}
Update restaurant tag
To update documents, use the following format: This will also update the restaurant tags of the restaurants that are using the tag.
Topic: hh.search.restaurantTags
{
"op": "update",
"payload": {
"id": 32,
"city_id": null, // null for all cities
"title_th": "อเมริกัน",
"title_en": "American",
"title_cn": "美国",
"category": "Cuisine",
"synonyms": ["United States", "USA"],
"total_restaurants": 100 // total restaurants using this tag
}
}
Full payload: restaurant_tags.json
Delete restaurant tag
To delete documents, use the following format: This will also delete the restaurant tags of the restaurants that are using the tag.
Topic: hh.search.restaurantTags
{
"op": "delete",
"payload": {
"id": 34
}
}
Restaurant Tag Groups Events
Update restaurant tag group
To update the tag group of a restaurant, use the following format: This will also update the restaurant tag group of the restaurants that are using the tag group.
Topic: hh.search.restaurantTagGroups
{
"op": "update",
"payload": {
"id": 1,
"title_en": "2 Night Stay 50% off",
"title_th": "2 Night Stay ลดสูงสุด 50%"
}
}
Delete restaurant tag group
To delete documents, use the following format: This will also delete the restaurant tag group of the restaurants that are using the tag group.
Topic: hh.search.restaurantTagGroups
{
"op": "delete",
"payload": {
"id": 1
}
}