Legacy Knowledge Base
Published Jun. 30, 2025

Is it possible to search web content using wildcards or a 'contains' clause?

Written By

Jose L. Bango

How To articles are not official guidelines or officially supporteddocumentation. They are community-contributed content and may not alwaysreflect the latest updates to Liferay DXP. We welcome your feedback toimprove How to articles!

While we make every effort to ensure this Knowledge Base is accurate, itmay not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with anyfeedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack"publication program, made available for informational purposes. Articlesin this program were published without a requirement for independentediting or verification and are provided "as is" withoutguarantee.

Before using any information from this article, independently verify itssuitability for your situation and project.

Issue

  • Entering keywords in the search bar can only search for the Web Content at the beginning of the keyword. For example, if there’s a web content named “Text_name”, the users can find the web content typing “text” in the search bar, but when the user types “name”, no results are displayed.
  • Can a 'contains' clause be emulated?

Environment

  • Liferay DXP 7.3
  • Liferay DXP 7.4

Resolution

  • There is no proper, built-in functionality to accomplish this directly
  • A story has been created to overcome this: 
    • LPD-4367 Allow users to search web content by noninitial partial name
  • However, while not recommended due to performance implications, a workaround does exist.

Workaround

  • You can go to System Settings > Search > Index Query Preprocessor, and add a new entry with the pattern for the desired field, for example, title.*. See Search Configuration Reference > Index Query Preprocessor.
    • Note: you must restart for the changes to take effect.
  • After that, if you perform a search, a 2-star wildcard is appended to your queries for fields matching your pattern. You can use the Search Insights widget to inspect the query sent to Elasticsearch. There you will see that a wildcard query is used for specific clauses.
    • For example:
      "wildcard": {
      "title_en_US": {
      "wildcard": "*keyword*"
      }
      }
  • However, make sure you understand the risks of doing this:
    • Wildcard queries with leading and trailing wildcards (*keyword*) have been known to be a bad pattern for years and are discouraged by Lucene and Elasticsearch/Solr as well.
    • The linked Index Query Preprocessor documentation highlights the fundamental problem with using this type of search:
      • This is a resource-intensive operation that degrades search engine performance as indexes grow larger.
    • In the product, this option was removed by default due to the severe performance issues it can cause. See LPS-130375.
      • In fact, the aforementioned configuration has been deprecated since 7.4.
    • In addition to that, Elasticsearch has a setting to disable these expensive queries (among others). See query-dsl-allow-expensive-queries:
      • The execution of such queries can be prevented by setting the value of the search.allow_expensive_queries setting to false (defaults to true).

Additional Information

Did this article resolve your issue ?

Legacy Knowledge Base