# Searching on a list of tags that all must match

**URL:** <https://discuss.elastic.co/t/searching-on-a-list-of-tags-that-all-must-match/117175>\
**Category:** Elasticsearch\
**Created:** [January 26, 2018, 9:25am UTC](https://discuss.elastic.co/t/searching-on-a-list-of-tags-that-all-must-match/117175 "2018-01-26T09:25:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![larsdolvik](https://avatars.discourse-cdn.com/v4/letter/l/cc9497/32.png) [@larsdolvik](https://discuss.elastic.co/u/larsdolvik)\
**Post date:** [January 26, 2018, 9:25am UTC](https://discuss.elastic.co/t/searching-on-a-list-of-tags-that-all-must-match/117175/1 "2018-01-26T09:25:25Z")

</div>

Hi,

Im pretty new to ElasticSearch and I am trying to build a Search Template in Mustache that takes an array of tags. At this point I am able to pass a params object containing the tags array, however, the problems start when I am trying to build an dynamic Search Template in Mustache.

The Tags array can contain from 1 to 6++ tags, which is the reason for the need of a dynamic Search Template.

I have tried using the Terms property, together with "minimum\_should\_match" at 100%, but it seems like its deprecated? Im running on ElasticSearch 2.3 at the moment.

My params object looks like this:  
{  
tags: ['tag1', 'tag2', 'tag3']  
}

And at this point I am stuck with this code for the Tags part of the search template:  
{{#tags}}  
"filter": {  
"terms": {  
"tags": ["{{tags}}"]  
}  
}  
{{/tags}}

This specific code now only gets the correct content when the Tags array contains only one tag. If it contains more the one tag, I got an parse error:  
[query\_parsing\_exception] Failed to parse, with { index="recipe-popularity-v1-2018-01-11@15:28:58" }

Kind regards  
LarsDolvik

---

<div class="post-metadata">

**Author:** ![s1monw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/s1monw/32/3637_2.png) [@s1monw](https://discuss.elastic.co/u/s1monw)\
**Post date:** [February 2, 2018, 10:13am UTC](https://discuss.elastic.co/t/searching-on-a-list-of-tags-that-all-must-match/117175/2 "2018-02-02T10:13:30Z")

</div>

you can do something like this:

```auto
GET _search/template
{
    "source": "{\"query\":{\"bool\":{\"must\": {{#toJson}}clauses{{/toJson}} }}}",
    "params": {
        "clauses": [
            { "term": { "tags" : "tag1" } },
            { "term": { "tags" : "tag2" } },
            { "term": { "tags" : "tag3" } }
        ]
   }
}

```

simon

---

<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 2, 2018, 10:13am UTC](https://discuss.elastic.co/t/searching-on-a-list-of-tags-that-all-must-match/117175/3 "2018-03-02T10:13:33Z")

</div>

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