Query Rules let you make precise, predetermined changes to your search results or search queries, thus allowing you to enhance search experience. For example, you can reposition items in a user’s search results or activate filters based on query terms. Rules can also be enabled for a fixed period of time: this makes Rules a great way of implementing sales or promotions. Query Rules are essentially If-This-Then-That construct - If search query contains 'Google', then promote 'Chromebook'. Query Rules serve a very specific purpose as far as search results and merchandising is concerned. When building a commercial search product, customers more often than not require commercializing the product based on certain search queries.

query rule dashboard

Query rules are available with Production I, II, III and IV cluster plans or with the Enterprise Plan for Self Hosted Appbase.io.

Use Cases

Here are some use cases where Query Rules can help you improve search relevance

  • Dynamically update facets based on query. Example if a user is searching for "laptops", show filters related laptops only
  • Promote result during discounts / sale on your store
  • Hide products that are not available
  • Hide irrelevant results
  • Replace search term based on data available

Configure If Condition

If conditions helps in deciding when to trigger a query rule based on which configured actions will be executed. There are 2 types of trigger

  1. Always:

    This is helpful when you want to execute an action with all the search request. Example you want to always hide a product which is no longer available in store.

  2. Condition

    This is helpful when you want to execute an action with specific search / filter condition. Example if query contains a specific search term. There are 4 types of search condition which you can configure

    • Query is: applied when there is an exact query match
    • Query contains: applied when a search query contains the specified query
    • Query starts with: applied when a search query starts with the specified query
    • Query ends with: applied when a search query ends with the specified query

    Here, you can also configure filter condition, which can help you set trigger based on filtering field and value. Example, `brand` is `apple`.

You can also configure rules for specific indexes in your ElasticSearch cluster and for a specific time period (example you only want to promote result for a seasonal sale on your ecommerce store ). By default, it is applicable on all the indexes and all the time.

configure if condition

Advanced Editor

Query Rules also comes with an advanced editor that allows writing truly expressive trigger conditions. A condition is of the form "$field $operator $value". It also allows combining conditions with AND/OR and ( ... ) clauses.

A condition can be expressed using one of the following operators. Each operator operates on the $field and $value.

Operator Name Description
exactlyMatches The field's value set by the search query should exactly match the provided value.
doesNotMatch The field's value set by the search query should not match the provided value.
contains The provided value is contained within the field's value set by the search query.
doesNotContain The provided value is not contained within the field's value set by the search query.
startsWith The field's value as set by the search query starts with the provided value.
doesNotStartWith The field's value as set by the search query does not start with the provided value.
endsWith The field's value as set by the search query ends with the provided value.
doesNotEndWith The field's value as set by the search query does not end with the provided value.
regularExpressionMatch Provide a regular expression to match the field's value as set by the search query with the provided value.

Here are some example conditions:

  1. $query exactlyMatches "iphone x"

  2. $query contains "iphone x" AND $query doesNotContain "iphone 8"

  3. $query contains "smart phone" AND brand exactlyMatches "apple"

  4. $query contains "smart phone" AND (brand exactlyMatches "apple" OR brand exactlyMatches "samsung")

Note: regexone is a great place to learn about regular expressions. regexr is a great online util to test your regular expressions.

Configure Then Actions

Then actions help you configure the actions that you want to invoke when triggering conditions are matched. Following are the actions that you can invoke

Note: Actions are executed in the order in which are the listed in your dashboard. You can drag and drop to change the sequence of executing actions.

Promote Results

Helps in promoting result at certain position in your result set. Example when a user searches for iphone you want to promote air pods.

promote result

Hide Results

Helps in hiding certain results from getting included in the actual search results. Example you want to hide products that not available in the store, or you want to hide results that contains irrelevant data.

hide result

Custom Data

Helps in sending the custom JSON data in search response. This will be helpful when you want to send some extra information to frontend, which can help in rendering more specific information.

custom data

Replace Search Term

Helps in replacing the user’s entire search query with another query. Helps in showing relevant results to users, specially when you are aware from the analytics that certain search term is returning no results.

replace search term

Remove Words

Removing words is the progressive loosening of query constraints to include more results when none are initially found.

For example, imagine an online smartphone shop that sold a limited inventory of iPhones in only 16GB and 32GB varieties. Users searching for “iphone 5 64gb” would see no results. This is not ideal behavior - it would be far better to show users some iPhone 5 results instead of a blank page.

You can remove multiple words by space separated values. E.g. iphone samsung.

remove words

Replace Words

Rules offers an alternative. You can now replace words instead of adding new ones. For example, if you make tv a synonym for television, Rules will replace tv with television so that only television is used to search.



Helps in doing more customization with search or handling edge cases around search relevancy. Functions lets you implement any custom action. Example you want to perform natural language processing on search query.


For more information you can read functions docs.

Note: a function linked with Query Rule cannot have its own triggering condition.