We need to implement a search functionality that focuses on specific fields, such as searching for the key phrase "chemical" within the title only, rather than searching the entire content of the page.
We have two different search requirements:
- A comprehensive content search with additional filters and facets.
- A lighter version that only searches specific fields, such as the title, rather than the entire page content.
We want to know if there's an option to specify the field to be searched within the REST API request object. For example, can we include the field in the request to search for a phrase?
Our goal is to use the same source for both types of searches without creating a separate source. We are simply looking for the flexibility to search within specific fields.
Here are our key questions:
- Is there a way to specify the field in the REST API request to limit the search to specific fields?
- If so, how can we structure the request to search within a specific field, like the title, without affecting the broader search functionality?
I appreciate any guidance or examples on how to achieve this.
Updated Info:
I tried the approach suggested by @ckhanna, but it returns results based on the "name" attribute instead of the "teasure_title" attribute.
Request:
{
"context": {
"page": {
"uri": "/search"
},
"locale": {
"country": "tt",
"language": "en"
}
},
"widget": {
"items": [
{
"rfk_id": "rfkid_7",
"entity": "mycontententity",
"sources": [
"1007450"
],
"search": {
"content": {
"fields":[
"name",
"teaser_title"
]
},
"query": {
"keyphrase": "listing",
"operator":"and",
"relevance": [
{
"name": "teaser_title",
"analyzer" : "Multi Locale Standard Analyzer",
"weight": 50
}
]
}
}
}
]
}
}
Response:
{
"widgets": [
{
"rfk_id": "rfkid_7",
"type": "content_grid",
"used_in": "page",
"entity": "mycontententity",
"content": [
{
"id": "e7837764f80840869a3a57b06ff834ab",
"name": "Listing pages - no mandatory tags",
"source_id": "1007450",
"teaser_title": "Consumer Product & Retail"
}
],
"total_item": 1,
"limit": 1,
"offset": 0
}
],
"dt": 8,
"ts": 1721752431005
}