# Macro in Elastic

**URL:** <https://discuss.elastic.co/t/macro-in-elastic/353276>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [February 14, 2024, 1:02pm UTC](https://discuss.elastic.co/t/macro-in-elastic/353276 "2024-02-14T13:02:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rachelei](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@rachelei](https://discuss.elastic.co/u/rachelei)\
**Post date:** [February 14, 2024, 1:02pm UTC](https://discuss.elastic.co/t/macro-in-elastic/353276/1 "2024-02-14T13:02:12Z")

</div>

We use macros stored in many queries to easily read the data and any change we need to make in the logic, we make the change in only one place and there is no need to access all the places that use the same logic to change them as well.  
What is the solution for this in Elastic?

---

<div class="post-metadata">

**Author:** ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)\
**Post date:** [February 14, 2024, 1:36pm UTC](https://discuss.elastic.co/t/macro-in-elastic/353276/2 "2024-02-14T13:36:27Z")

</div>

Hi @rachelei - sounds like you might be looking for [search templates](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html). These are also leveraged in [search applications](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-application-overview.html) which you may find useful.

---

<div class="post-metadata">

**Author:** ![rachelei](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@rachelei](https://discuss.elastic.co/u/rachelei)\
**Post date:** [February 15, 2024, 7:57am UTC](https://discuss.elastic.co/t/macro-in-elastic/353276/3 "2024-02-15T07:57:28Z")

</div>

I want to clarify again to make sure your answer does answer my question.  
I have a long and complex basic query and it serves as a basis for many other queries.  
Until today (in another system) I used a macro command, every time I wanted to write the base query and add additional criteria to it, I used the name of the macro (an alias of the query) and added what was needed to it. (Sometimes in one query I used several different aliases) This is how the alias looks like: `Azure_last_report`, etc.  
Now I want to transfer the complex query to Elastic, using ESQL.  
Is it possible to save the same long and basic query with a specific name and in every new search that I create and have to use it as a basis for the search, I can use its alias and I won't have to write it down in full?  
In a search template, it seems that only syntaxes / variables can be saved and not a full query, right?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 14, 2024, 7:57am UTC](https://discuss.elastic.co/t/macro-in-elastic/353276/4 "2024-03-14T07:57:57Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
