Optimizing Search Response Size
In rare cases, an overly large search response can result in ERROR messages from the search engine:
ERROR [http-nio-8080-exec-335][ElasticsearchIndexSearcher:165] java.lang.RuntimeException: java.io.IOException: entity content is too long [117672846] for the configured buffer limit [104857600]
If too many large documents are returned in the response, the response size can become larger than the maximum allowed response size. You can shrink the response size with a search blueprint in these ways:
- By filtering the fields returned by the search engine
- By excluding the source field from the response
Filtering Fields
By default, Liferay requests all mapped fields from Elasticsearch. Fields are specified in the mappings:
"userId": {
"type": "keyword"
},
Usually, returning all mapped fields is innocuous. In rare cases, an overly large response can result in ERROR messages indicating that the returned content is too long for the configured buffer limit.
To reduce the response size of searches and improve performance generally, you can filter the returned fields. For this you must create a Search Blueprint in the Advanced Configuration field with JSON like this:
{
"fields": [
"userId"
]
}
This communicates that only the userId
field should be returned in each document.
If you inspect the response or use the View Results in Document Form setting in the Search Results widget, you can see that more fields are returned than those declared in fields
. Liferay’s search framework automatically adds certain fields needed for Liferay to function properly, such as entryClassName
, entryClassPK
, and companyId
.
Returning Fields for Summaries in the Search Results Widget
The Search Results widget requires certain fields in the response for generating result summaries. The summary fields are asset-specific, but many assets require at least the localized version of the title, content, and description fields.
Your use case determines the fields you should return in the response.
Fields available for display in the Search Results summaries are defined by the Search Results widget’s display logic (SearchResultsSummaryDisplayBuilder
and SearchResultsSummaryDisplayContext
).
Excluding the Source Field
The _source
field contains the original document body that was passed to the index request. This field is not itself indexed, but is stored and returned in the search response for each document. If you encounter errors from a too large search response, you can exclude the _source
field.
To exclude the source field, you must set fetchSource
to false
in the Advanced Configuration of a blueprint:
{
"source": {
"fetchSource": false
}
}
As demonstrated in the following example, you can exclude the source field and limit the returned fields simultaneously.
Example: Limiting the Fields Returned in the Search Response
Although uncommon, searching in a system with lots of translated content can produce a search response that’s too large. One workaround is to disable unneeded locales in Liferay, to avoid returning more translated fields than necessary. Another approach is trimming the response with a search blueprint, as described here:
-
First add a web content article. Open the Site menu () and go to Content & Data → Web Content.
-
Click Add () → Basic Web Content and give it this content:
- Title: Web Content Article Title
- Description: Web Content Article Description
- Content: Web Content Article Content
-
Open the Global Menu () → Applications → Blueprints (Search Experiences).
-
Click Add ().
-
Name the blueprint Filter Fields.
-
Open the blueprint’s Preview screen, and search for web content.
-
Expand the document preview for the web content you created and observe that the document contains many fields:
-
Click Configuration.
-
Replace the contents of the Advanced Configuration field with this:
{ "source": { "fetchSource": false }, "fields": [ "content_${context.language_id}", "description_${context.language_id}", "title_${context.language_id}" ] }
This configuration specifies that only the content, description, and title fields of the current session language should be returned in the response.
-
Open the blueprint’s Preview screen, and search for web content again.
-
Expand the document preview for the Test Test user and observe that the document contains only the fields you specified and a few added by Liferay’s search framework:
Excluding the source field and filtering the returned fields is rarely needed, but can be helpful if you’re encountering search engine error messages about the response being too large.