OpenSearch Query Examples
Examples of OpenSearch queries used by the HH Search Service.
Note: Adjust
sizeandfromfor pagination (default: 10 results starting at 0).
Filter by availability
This query is used to filter restaurants by availability. The query will return restaurants that have availability on a specific date and time and have at least 5 available seats for adults.
Parameters:
availability.date_time: The date and time of the availability (format:YYYY-MM-DDTHH:mm).availability.adult: Minimum required available seats for adults.
// GET restaurants/_search
{
"query": {
"bool": {
"must": [],
"should": [],
"filter": [
{
"nested": {
"path": "availability",
"query": {
"bool": {
"filter": [
{
"term": {
"availability.date_time": "YYYY-MM-DDTHH:mm"
}
},
{
"range": {
"availability.adult": {
"gte": 5
}
}
}
]
}
}
}
}
]
}
},
"sort": [
{
"_score": {
"order": "desc"
},
"top_gmv": {
"order": "desc"
}
}
],
"size": 10,
"from": 0,
"_source": {
"include": [
"id",
"name_en",
"name_th",
"name_cn",
"availability"
]
}
}
Filter by cuisines and dining styles
This query is used to filter restaurants by cuisines and dining styles. The query will return restaurants that serve at least one of the specified cuisines and have at least one of the specified dining styles.
Parameters:
Required Filters
cuisines.id: The IDs of the cuisines.dining_styles.id: The IDs of the dining styles.
Boosting Parameters
primary_cuisine.id: The IDs of the primary cuisines.primary_dining_style.id: The IDs of the primary dining styles.
Primary fields in the
shouldclause boost matching restaurants but aren’t required for results.
// GET restaurants/_search
{
"query": {
"bool": {
"must": [
{
"terms": {
"cuisines.id": [
"11",
"15"
]
}
},
{
"terms": {
"dining_styles.id": [
"1643",
"1645"
]
}
}
],
"should": [
{
"terms": {
"primary_cuisine.id": [
"11",
"15"
]
}
},
{
"terms": {
"primary_dining_style.id": [
"1643",
"1645"
]
}
}
],
"filter": []
}
},
"sort": [
{
"_score": {
"order": "desc"
},
"top_gmv": {
"order": "desc"
}
}
],
"size": 10,
"from": 0,
"_source": {
"include": [
"id",
"name_en",
"name_th",
"name_cn",
"availability",
"cuisines",
"dining_styles"
]
}
}
Filter by price_range
Returns restaurants where either lowest_price OR highest_price falls within the specified range. Note: this uses OR logic - restaurants matching either price condition will be included. The should clause is used so that a restaurant matches if either price bound falls within the range, while top_gmv still drives relevance in the sort.
Parameters:
price_per_person.lowest_price: Lower bound of the price filter range (in THB).price_per_person.highest_price: Upper bound of the price filter range (in THB).
The
lowest_price/highest_pricepair defines the filter range: a restaurant is included if either bound falls within thegte/ltevalues.Excluding fields here demonstrates response filtering - adjust based on required data.
// GET restaurants/_search
{
"query": {
"bool": {
"must": [],
"should": [
{
"range": {
"price_per_person.lowest_price": {
"gte": 0,
"lte": 2000
}
}
},
{
"range": {
"price_per_person.highest_price": {
"gte": 0,
"lte": 2000
}
}
}
],
"filter": []
}
},
"sort": [
{
"_score": {
"order": "desc"
},
"top_gmv": {
"order": "desc"
}
}
],
"size": 10,
"from": 0,
"_source": {
"exclude": [
"id",
"name_en",
"name_th",
"name_cn",
"price"
]
}
}