Rule: Bulk Rewriting by Query#
This rule allows you to completely rewrite element values based on pre-defined product queries. It can be used for automatically setting values for different product segments (e.g., setting prices, manufacturers, or labels).
Extra features#
- Prefill left side – loads values from the input feed for the selected element
- Remove rows without values
- New values can include:
- plain text
- a variable
- an empty value
Practical examples#
Example 1: Set CPC value based on product queries#
This example shows how to use the Bulk Rewriting by Query rule to set different CPC values for different product segments.
1. Creating a new rule:
- Open the “Rules” page.
- Click the New rule button.
2. Selecting the rule type:
- In the Rule type field, select the Bulk Rewriting by Query option.
3. Choosing the element to change:
- In the Element field, select the element you want to modify.
- In our case, this will be the
HEUREKA_CPCelement.
4. Product queries:
- In the left column in the Query field
- from the Selectbox, choose prepared saved queries from the project, each on a separate row, or
- click the Prefill left side button and Mergado will prefill all existing queries from the project in the left column
- Delete the rows containing queries you do not want to use
- 💡 Tip: This is useful when you want to use most of the existing queries in the project.
- from the Selectbox, choose Create new query and create new Product queries for specific products you want the rule to apply to.
5. Enter the new value:
- In the right column, in the “New value” field, enter for each row:
- a text value, for example: the specific CPC amount (
15) - You can also use a variable or combination of variable and text, but this is not suitable for our example
- a text value, for example: the specific CPC amount (
6. Naming the rule:
- In the last step, enter the rule name, for example “Set CPC”.
Example 2: Set manufacturer based on queries#
This example shows how to use the Bulk Rewriting by Query rule to automatically set different manufacturers for different product segments.
1. Creating a new rule:
- Open the “Rules” page.
- Click the New rule button.
2. Selecting the rule type:
- In the Rule type field, select the Bulk Rewriting by Query option.
3. Choosing the element to change:
- In the Element field, select the element you want to modify.
- In our case, this will be the
g:brandelement.
4. Product queries:
- In the left column in the Query field
- from the Selectbox, choose prepared saved queries from the project, each on a separate row, or
- click the Prefill left side button and Mergado will prefill all existing queries in the left column
- Delete the rows containing queries you do not want to use
- This is useful when you want to use most of the existing queries in the project.
- from the Selectbox, choose Create new query and create new Product queries for specific products you want the rule to apply to.
5. Enter the new value:
- In the right column, in the “New value” field, enter for each row:
- a text value, for example: the specific manufacturer (
Nike) - You can also use a variable or combination of variable and text, but this is not suitable for our example
- a text value, for example: the specific manufacturer (
6. Naming the rule:
- In the last step, enter the rule name, for example “Set manufacturer”.
Example 3: Set the custom_label element based on price ranges#
This example shows how to use the Bulk Rewriting by Query rule to set custom_label tags for different price ranges.
1. Creating a new rule:
- Open the “Rules” page.
- Click the New rule button.
2. Selecting the rule type:
- In the Rule type field, select the Bulk Rewriting by Query option.
3. Choosing the element to change:
- In the Element field, select the element you want to modify.
- In our case, this will be the
g:custom_label_0element.
4. Product queries:
- In the left column in the Query field
- from the Selectbox, choose prepared saved queries from the project, each on a separate row, or
- click the Prefill left side button and Mergado will prefill all existing queries in the left column
- Delete the rows containing queries you do not want to use
- This is useful when you want to use most of the existing queries in the project.
- from the Selectbox, choose Create new query and create new Product queries for specific products you want the rule to apply to.
5. Enter the new value:
- In the right column, in the “New value” field, enter for each row:
- the text value of the new label for the given query, for example: label_1 (
Heroes) - You can also use a variable or combination of variable and text, but this is not suitable for our example
- the text value of the new label for the given query, for example: label_1 (
6. Naming the rule:
- In the last step, enter the rule name, for example “Set g:custom_label_0”.
Additional uses#
- Set custom_label based on margin levels
- Add GPSR data (responsible person for placing on the EU market) to the feed
- Set categories based on queries
FAQ#
What is the Bulk Rewriting by Query rule for?#
This rule allows you to automatically rewrite a single element with different values for different product queries. You can use it, for example, to set cost per click (CPC), manufacturer (brand), or labels (custom_label) for different product groups.
What is the difference between this rule and the standard Rewrite rule?#
The Rewrite rule changes the value in different elements for a single Product query. The Bulk Rewriting by Query rule allows you to set different values for different product queries for a single element – all within one rule.
How can I quickly load all existing queries into the rule?#
Click the “Prefill left side” button. Mergado will automatically load all saved product queries from the project into the left column. You can then delete the rows you do not want to use.
What should I do if the query I need does not exist yet?#
Choose the “Create new query” option directly in the “Query” field. This allows you to create a new Product query without leaving the rule editor.
Can I combine text and variables in the “New value” field?#
Yes. In the “New value” field, you can use:
- text (e.g.,
Nike), - a variable (e.g.,
%brand%), - or a combination (e.g.,
%brand% -- new collection).
💡 Most cases with this rule use plain text, but variables are supported.
What does the “Remove rows without values” function do?#
This function automatically deletes all empty rows in the rule where the value in the “New value” field is missing. This keeps the rule cleaner and prevents slowdowns during evaluation.
What happens if a product falls into multiple queries?#
Mergado processes rows from top to bottom. If a product matches multiple queries, the value from the last matching row from the top is used. Row order therefore affects the result.
Can I use the rule to set CPC for different product categories?#
Yes. Create a separate query for each category (e.g., “Kitchen Appliances”, “Mobile Phones”) and in the “New value” field for each row, enter the corresponding CPC (e.g., 15, 25, 30). This way, you can set different CPC values for different product segments.
How can I use this rule to set different manufacturers (brand) for different products?#
Create product queries as needed (e.g., by name, category, or supplier). Then in the “Element” field, select g:brand and in the right column “New value”, enter the manufacturer names:
- Query “Shoes” → value:
Nike - Query “Backpacks” → value:
Osprey - Query “T-shirts” → value:
Adidas.
How do I use the rule to set labels (custom_label) based on price ranges?#
In the left column, create queries by price (e.g., Price < 500, Price 500-1000, Price > 1000). In the right column, in the “New value” field, enter the labels:
- Query 1 →
label_low - Query 2 →
label_medium - Query 3 →
label_high.
This way, you assign dynamic labels to products based on their price.
Can I use the rule to remove a value for selected products?#
Yes. If you leave the “New value” field empty for a row, Mergado will delete the given element for all products that belong to that query.
Can the rule be scheduled to run only on specific days (e.g., during a seasonal campaign)?#
Yes. Using the Timer, you can specify when the rule should be active – for example, only on weekends or within a specific date range (e.g., July 1–15). This is useful for temporary adjustments like seasonal labels, promotional CPC, or promo brands.
How do I know which queries the rule already uses?#
All active queries used in the rule are listed in the left column. If you used the “Prefill left side” function, the complete list of all project queries is displayed here. You can manually delete or edit those you do not want to use.
What happens if I use an incorrect variable or an empty value in the “New value” field?#
If Mergado does not recognize the variable, the element remains unchanged. Such a variable will have a red background instead of green, indicating an error or a non-existent element. An empty value, on the other hand, causes the element to be deleted (replaced with an empty string). It is recommended to test the rule on a smaller sample of products using the Rule walkthrough.
Can I change multiple elements at once with this rule?#
No. Within a single “Bulk Rewriting by Query” rule, you can work with only one selected element (e.g., g:brand or HEUREKA_CPC).
How do I check if the changes were applied correctly?#
After saving and applying the rules or after regenerating the feed, open the product preview or use the “Rule walkthrough” feature. You will see how the element value changes based on the selected queries and whether the new data was correctly written to the output.
Can this rule be used for adding GPSR data or other regulatory information?#
Yes. Using queries, you can determine which products fall under specific regulations (e.g., cosmetics, food). In the “Element” field, select the relevant element (e.g., g:responsible_person) and in the “New value” field, enter the responsible person or entity.