# Eval script inside field

**URL:** https://discuss.elastic.co/t/eval-script-inside-field/269816
**Category:** Elasticsearch
**Tags:** painless
**Created:** [April 11, 2021, 3:29pm UTC](https://discuss.elastic.co/t/eval-script-inside-field/269816 "2021-04-11T15:29:46Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![opak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/opak/32/5705_2.png) [@opak](https://discuss.elastic.co/u/opak)
#### Post date: [April 11, 2021, 3:29pm UTC](https://discuss.elastic.co/t/eval-script-inside-field/269816/1 "2021-04-11T15:29:46Z")

</div>

Hello, i have a question how to eval script which can be stored inside a field.

For example, i want to define rules for calculation inside documents. Let's see on this mapping:

index: rules

```auto
{
  "properties": {
    "price_rule": { "type": "keyword" }
  }
}

```

Then i add document:

```auto
curl -X PUT localhost:9200/rules/_doc/1 -d '{"price_rule": " if (params.Age <= 60) { return 20 } else { return 30}"}' -H "Content-Type: application/json"

```

And i want todo a request for search, where i can send para age and see which documents has price\_rule \> 20 as example.

```auto
{
  "query": {
    "bool" : {
      "filter" : {
        "script" : {
          "script" : {
            "source" : "doc['price_rule'].value",
            "lang" : "painless",
            "params" : {
              "Age" : "60"
            }
          }
        }
      }
    }
  }
}

```

How i can eval script inside field and pass params?

---

<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 9, 2021, 3:30pm UTC](https://discuss.elastic.co/t/eval-script-inside-field/269816/2 "2021-05-09T15:30:45Z")

</div>

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