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:

  1. By filtering the stored fields returned by the search engine
  2. By excluding the source field from the response

Filtering Stored Fields

By default, Liferay requests all stored fields from Elasticsearch. Stored fields are specified in the mappings:

"userId": {
   "store": true,
   "type": "keyword"
},

Usually, returning all stored 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 stored fields. For this you must create a Search Blueprint in the Advanced Configuration field with JSON like this:

{
   "stored_fields": [
      "userId"
   ]
}

This communicates that only the userId field should be returned in each document.

Note

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 stored_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.

Web Content result summaries show several fields.

Your use case determines the stored 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 stored 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:

  1. First add a web content article. Open the Site menu (Site menu) and go to Content & DataWeb Content.

  2. Click Add (Add) → Basic Web Content and give it this content:

    • Title: Web Content Article Title
    • Description: Web Content Article Description
    • Content: Web Content Article Content
  3. Open the Global Menu (Global Menu) → Applications → Blueprints (Search Experiences).

  4. Click Add (Add).

  5. Name the blueprint Filter Stored Fields.

  6. Open the blueprint’s Preview screen, and search for web content.

  7. Expand the document preview for the web content you created and observe that the document contains many fields:

    This web content article has many fields.

  8. Click Configuration.

  9. Replace the contents of the Advanced Configuration field with this:

    {
       "source": {
          "fetchSource": false
       },
       "stored_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.

  10. Open the blueprint’s Preview screen, and search for web content again.

  11. 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:

    After filtering, only Liferay's required fields and those you specified are returned in the response.

Excluding the source field and filtering the stored fields is rarely needed, but can be helpful if you’re encountering search engine error messages about the response being too large.

Capabilities

Product

Contact Us

Connect

Powered by Liferay
© 2024 Liferay Inc. All Rights Reserved • Privacy Policy