Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

Event Operations

The events can have the following operations:

OperationDescription
indexFull reindex the documents with the new data
createAdd new documents to the index
updateUpdate documents in the index
deleteDelete documents from the index

Event Payload

The payload of the event is a JSON object with the following fields:

FieldTypeDescription
opStringThe type of the event (index, create, update, delete)
batch_numberIntegerThe batch number of the event. The batch number starts from 0.
total_itemsIntegerThe total number of all items to be indexed (sum of all batches).
job_idStringThe Sidekiq job ID (JID) of the job that generated the event.
payloadArray, ObjectThe documents to be indexed, updated or deleted. The structure of the documents is specific to each index.

Kafka Topics

  1. {namespace}.hh.search.restaurants
  2. {namespace}.hh.search.restaurants.availability
  3. {namespace}.hh.search.restaurants.tags
  4. {namespace}.hh.search.restaurants.tagGroups
  5. {namespace}.hh.search.restaurantTags
  6. {namespace}.hh.search.restaurantTagGroups

Note: {namespace} is the namespace of the environment environment name (e.g. ballbot, engineering, venus, staging, production).

EnvironmentNamespaceDomain
Developmentlocalhostlocalhost:4000
Ballbotballbothh-ballbot.my.id
Engineeringengineeringhh-engineering.my.id
Venusvenushh-venus.my.id
Stagingstaginghhstaging.dev
Productionproductionhungryhub.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
  }
}