# Moustache search templates are too limited

**URL:** <https://discuss.elastic.co/t/moustache-search-templates-are-too-limited/19578>\
**Category:** Elasticsearch\
**Created:** [September 2, 2014, 9:33pm UTC](https://discuss.elastic.co/t/moustache-search-templates-are-too-limited/19578 "2014-09-02T21:33:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Damian\_Wood](https://avatars.discourse-cdn.com/v4/letter/d/ee59a6/32.png) [@Damian\_Wood](https://discuss.elastic.co/u/Damian_Wood)\
**Post date:** [September 2, 2014, 9:33pm UTC](https://discuss.elastic.co/t/moustache-search-templates-are-too-limited/19578/1 "2014-09-02T21:33:44Z")

</div>

I want to use search templates to generate a query based on the value of a  
parameter (not its presence or being True).

For example I have a sortType parameter that can be {nearest, cheapest,  
easiest, newest}. Each of these options causes a drastically different  
change to the query sent to ES.

I'm assuming that I'm currently limited to creating a boolean flag and  
checking for the presence of sortType\_nearest, sortType\_cheapest etc.

It would be nice to have a template language supported that included an if  
statement.

Apologies if this has already been mentioned, but I searched and couldn't  
find anything.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c7ac6071-bd43-4e64-8571-c8036b0d9218%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c7ac6071-bd43-4e64-8571-c8036b0d9218%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 3, 2014, 9:58am UTC](https://discuss.elastic.co/t/moustache-search-templates-are-too-limited/19578/2 "2014-09-03T09:58:20Z")

</div>

Ok I'll bite, what do you mean by moustache search?

Regards,  
Mark Walkom

Infrastructure Engineer  
Campaign Monitor  
email: [markw@campaignmonitor.com](mailto:markw@campaignmonitor.com)  
web: [www.campaignmonitor.com](http://www.campaignmonitor.com)

On 3 September 2014 07:33, Damian Wood [damian.woood9006@gmail.com](mailto:damian.woood9006@gmail.com) wrote:

> I want to use search templates to generate a query based on the value of a  
> parameter (not its presence or being True).
> 
> For example I have a sortType parameter that can be {nearest, cheapest,  
> easiest, newest}. Each of these options causes a drastically different  
> change to the query sent to ES.
> 
> I'm assuming that I'm currently limited to creating a boolean flag and  
> checking for the presence of sortType\_nearest, sortType\_cheapest etc.
> 
> It would be nice to have a template language supported that included an if  
> statement.
> 
> Apologies if this has already been mentioned, but I searched and couldn't  
> find anything.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/c7ac6071-bd43-4e64-8571-c8036b0d9218%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c7ac6071-bd43-4e64-8571-c8036b0d9218%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/c7ac6071-bd43-4e64-8571-c8036b0d9218%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c7ac6071-bd43-4e64-8571-c8036b0d9218%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAEM624a8DxOd%3DoW8NKB7\_PuPCm%3D0kzz974AJSiNZf5j3KqhiLA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAEM624a8DxOd%3DoW8NKB7_PuPCm%3D0kzz974AJSiNZf5j3KqhiLA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Damian\_Wood](https://avatars.discourse-cdn.com/v4/letter/d/ee59a6/32.png) [@Damian\_Wood](https://discuss.elastic.co/u/Damian_Wood)\
**Post date:** [September 3, 2014, 2:42pm UTC](https://discuss.elastic.co/t/moustache-search-templates-are-too-limited/19578/3 "2014-09-03T14:42:21Z")

</div>

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On Wednesday, September 3, 2014 10:59:09 AM UTC+1, Mark Walkom wrote:

> Ok I'll bite, what do you mean by moustache search?
> 
> Regards,  
> Mark Walkom
> 
> Infrastructure Engineer  
> Campaign Monitor  
> email: [ma...@campaignmonitor.com](mailto:ma...@campaignmonitor.com) \<javascript:\>  
> web: [www.campaignmonitor.com](http://www.campaignmonitor.com)
> 
> On 3 September 2014 07:33, Damian Wood \<[damian.w...@gmail.com](mailto:damian.w...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > I want to use search templates to generate a query based on the value of  
> > a parameter (not its presence or being True).
> > 
> > For example I have a sortType parameter that can be {nearest, cheapest,  
> > easiest, newest}. Each of these options causes a drastically different  
> > change to the query sent to ES.
> > 
> > I'm assuming that I'm currently limited to creating a boolean flag and  
> > checking for the presence of sortType\_nearest, sortType\_cheapest etc.
> > 
> > It would be nice to have a template language supported that included an  
> > if statement.
> > 
> > Apologies if this has already been mentioned, but I searched and couldn't  
> > find anything.
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/c7ac6071-bd43-4e64-8571-c8036b0d9218%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c7ac6071-bd43-4e64-8571-c8036b0d9218%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/c7ac6071-bd43-4e64-8571-c8036b0d9218%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c7ac6071-bd43-4e64-8571-c8036b0d9218%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5096b6d9-fa58-4e52-9d45-7c7908d1a483%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5096b6d9-fa58-4e52-9d45-7c7908d1a483%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Damian\_Wood](https://avatars.discourse-cdn.com/v4/letter/d/ee59a6/32.png) [@Damian\_Wood](https://discuss.elastic.co/u/Damian_Wood)\
**Post date:** [September 3, 2014, 2:44pm UTC](https://discuss.elastic.co/t/moustache-search-templates-are-too-limited/19578/4 "2014-09-03T14:44:17Z")

</div>

Ahh sorry, typo. I meant "mustache".

On Wednesday, September 3, 2014 10:59:09 AM UTC+1, Mark Walkom wrote:

> Ok I'll bite, what do you mean by moustache search?
> 
> Regards,  
> Mark Walkom
> 
> Infrastructure Engineer  
> Campaign Monitor  
> email: [ma...@campaignmonitor.com](mailto:ma...@campaignmonitor.com) \<javascript:\>  
> web: [www.campaignmonitor.com](http://www.campaignmonitor.com)
> 
> On 3 September 2014 07:33, Damian Wood \<[damian.w...@gmail.com](mailto:damian.w...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > I want to use search templates to generate a query based on the value of  
> > a parameter (not its presence or being True).
> > 
> > For example I have a sortType parameter that can be {nearest, cheapest,  
> > easiest, newest}. Each of these options causes a drastically different  
> > change to the query sent to ES.
> > 
> > I'm assuming that I'm currently limited to creating a boolean flag and  
> > checking for the presence of sortType\_nearest, sortType\_cheapest etc.
> > 
> > It would be nice to have a template language supported that included an  
> > if statement.
> > 
> > Apologies if this has already been mentioned, but I searched and couldn't  
> > find anything.
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/c7ac6071-bd43-4e64-8571-c8036b0d9218%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c7ac6071-bd43-4e64-8571-c8036b0d9218%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/c7ac6071-bd43-4e64-8571-c8036b0d9218%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c7ac6071-bd43-4e64-8571-c8036b0d9218%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2c2a9200-35ed-43e3-9fe6-ec880806ddb6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2c2a9200-35ed-43e3-9fe6-ec880806ddb6%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Itamar\_Syn\_Hershko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itamar_syn_hershko/32/725_2.png) [@Itamar\_Syn\_Hershko](https://discuss.elastic.co/u/Itamar_Syn_Hershko)\
**Post date:** [September 3, 2014, 9:26pm UTC](https://discuss.elastic.co/t/moustache-search-templates-are-too-limited/19578/5 "2014-09-03T21:26:51Z")

</div>

Templates in general should be logic-less, hence I support the decision of  
using mustache. Support of handlebars and maybe also some help from Lucene  
expressions may indeed come in handy, but still there may be ways of  
achieving what you are after also using mustache

I think this SO answer summarizes all this very well:

> <https://stackoverflow.com/questions/15041930/mustache-conditions-and-loops/15041966#15041966>

--

Itamar Syn-Hershko  
[http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
Freelance Developer & Consultant  
Author of RavenDB in Action [http://manning.com/synhershko/](http://manning.com/synhershko/)

On Wed, Sep 3, 2014 at 12:33 AM, Damian Wood [damian.woood9006@gmail.com](mailto:damian.woood9006@gmail.com)  
wrote:

> I want to use search templates to generate a query based on the value of a  
> parameter (not its presence or being True).
> 
> For example I have a sortType parameter that can be {nearest, cheapest,  
> easiest, newest}. Each of these options causes a drastically different  
> change to the query sent to ES.
> 
> I'm assuming that I'm currently limited to creating a boolean flag and  
> checking for the presence of sortType\_nearest, sortType\_cheapest etc.
> 
> It would be nice to have a template language supported that included an if  
> statement.
> 
> Apologies if this has already been mentioned, but I searched and couldn't  
> find anything.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/c7ac6071-bd43-4e64-8571-c8036b0d9218%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c7ac6071-bd43-4e64-8571-c8036b0d9218%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/c7ac6071-bd43-4e64-8571-c8036b0d9218%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c7ac6071-bd43-4e64-8571-c8036b0d9218%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAHTr4Zu0oDyRHke3fF06jNx-syL9SMOjXfCNaTbKNTv%3Dp-Ca8w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHTr4Zu0oDyRHke3fF06jNx-syL9SMOjXfCNaTbKNTv%3Dp-Ca8w%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 1:04am UTC](https://discuss.elastic.co/t/moustache-search-templates-are-too-limited/19578/6 "2017-07-06T01:04:31Z")

</div>


