# Search template condition on paramters

**URL:** <https://discuss.elastic.co/t/search-template-condition-on-paramters/293809>\
**Category:** Elasticsearch\
**Created:** [January 8, 2022, 7:25pm UTC](https://discuss.elastic.co/t/search-template-condition-on-paramters/293809 "2022-01-08T19:25:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ylasri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ylasri/32/86120_2.png) [@ylasri](https://discuss.elastic.co/u/ylasri)\
**Post date:** [January 8, 2022, 7:25pm UTC](https://discuss.elastic.co/t/search-template-condition-on-paramters/293809/1 "2022-01-08T19:25:37Z")

</div>

Hello Everybody, Happy new year 2022.

I have a small use case that i want to implement using Elasticsearch search template  
The idea is to limit the parameter `from` so that it can't go more that a limit value.

Do you have any idea on how to force the parameter `from` to not to go more than the value of `max` parameter ?

The search template would be something like this, i wasn't able to find a way to implement this kind of condition

`if params.from > params.max then params.max else params.from`

```auto
POST _render/template
{
  "source": {
    "query": {
      "match": {
        "message": "{{query_string}}"
      }
    },
    "from": "{{from}}{{^from}}0{{/from}}",
    "size": "{{size}}{{^size}}10{{/size}}"
  },
  "params": {
    "query_string": "hello world",
    "from": 0,
    "size": 15,
    "max": 25
  }
}

```

---

<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:** [February 5, 2022, 7:26pm UTC](https://discuss.elastic.co/t/search-template-condition-on-paramters/293809/2 "2022-02-05T19:26:20Z")

</div>

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