# How to use Mustache script in percolator

**URL:** <https://discuss.elastic.co/t/how-to-use-mustache-script-in-percolator/129577>\
**Category:** Elasticsearch\
**Created:** [April 26, 2018, 3:00am UTC](https://discuss.elastic.co/t/how-to-use-mustache-script-in-percolator/129577 "2018-04-26T03:00:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anoopvalluthadam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anoopvalluthadam/32/30286_2.png) [@anoopvalluthadam](https://discuss.elastic.co/u/anoopvalluthadam)\
**Post date:** [April 26, 2018, 3:00am UTC](https://discuss.elastic.co/t/how-to-use-mustache-script-in-percolator/129577/1 "2018-04-26T03:00:58Z")

</div>

we are using Mustache script in the query to use params, since script contains `Pattern` and painless doesn't support parameterizing `Pattern`.

query:

```
PUT test_index/notification/ID
{
    "source": {
        "query": {
            "bool": {
                "must": [
                    {
                        "bool": {
                            "must": {
                                "bool": {
                                    "should": [
                                        {
                                            "bool": {
                                                "must": [
                                                    {
                                                        "query_string": {
                                                            "query": "a*",
                                                            "quote_analyzer": "standard",
                                                            "allow_leading_wildcard": "true",
                                                            "analyze_wildcard": "true",
                                                            "default_operator": "AND",
                                                            "phrase_slop": 1
                                                        }
                                                    },
                                                    {
                                                        "script": {
                                                            "script": {
                                                                "source": "Pattern p = {{param_0}}; p.matcher(params._source.summary ?: '').find();",
                                                                "lang": "painless"
                                                            }
                                                        }
                                                    }
                                                ]
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    }
                ]
            }
        },
        "sort": [
            {
                "headline.case_insensitive_sort_raw": "asc"
            }
        ]
    },
    "params": {
        "param_0": "/\\s?a\\S*?/i"
    }
}

```

and percolator search is:

```
GET test_index/_search
{
  "query": {
    "percolate": {
      "field": "query",
      "document_type": "doctype",
      "index": "document_index_testing",
      "type": "mediaitems",
      "id": "262587721"
    }
    
  }
}

```

and it is not matching. If the percolator query using `painless`, it works fine.

is there any way to make `Mustache` script works in `Percolator`

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [April 27, 2018, 4:01pm UTC](https://discuss.elastic.co/t/how-to-use-mustache-script-in-percolator/129577/2 "2018-04-27T16:01:28Z")

</div>

Your percolate example isn't actually using the template you defined. To do this, you would need to include percolate inside your template query, and have your search [use the template](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/query-dsl-template-query.html).

However, regarding your use of painless, this is going to be very inefficient and most likely hit default compilation limits. While it will be similarly inefficient, have you tried the [regex query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html)?

---

<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:** [May 25, 2018, 4:01pm UTC](https://discuss.elastic.co/t/how-to-use-mustache-script-in-percolator/129577/3 "2018-05-25T16:01:29Z")

</div>

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