# Using Painless Script with Lucene Query in ElasticSearch

**URL:** <https://discuss.elastic.co/t/using-painless-script-with-lucene-query-in-elasticsearch/150571>\
**Category:** Elasticsearch\
**Created:** [October 1, 2018, 1:08pm UTC](https://discuss.elastic.co/t/using-painless-script-with-lucene-query-in-elasticsearch/150571 "2018-10-01T13:08:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomTom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomtom/32/3676_2.png) [@TomTom](https://discuss.elastic.co/u/TomTom)\
**Post date:** [October 1, 2018, 1:08pm UTC](https://discuss.elastic.co/t/using-painless-script-with-lucene-query-in-elasticsearch/150571/1 "2018-10-01T13:08:09Z")

</div>

I needed to create a function in Painless to perform multiple field checks of a document and return if a value is in a range of 0 to 2. This Painless script uses parameters with names, such as 'current\_timestamp', which are entered manually.

Is possible use this script in a search in ElasticSearch when it is made using only Lucene Query and not the default JSON of the ES?

I tried to perform a search that way, but it doesn't work.

```auto
{
    "from": 0,
    "size": 30,
    "sort": {
        "id": {
            "order": "desc"
        }
    },
    "query": {
        "query_string": {
            "query": "isvalid({current_timestamp:1538081255011}):2"
        }
    }
}

```

---

<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:** [October 3, 2018, 11:39pm UTC](https://discuss.elastic.co/t/using-painless-script-with-lucene-query-in-elasticsearch/150571/2 "2018-10-03T23:39:41Z")

</div>

It's not possible to do this inside a lucene query. You will need to use a [script query](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/query-dsl-script-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:** [October 31, 2018, 11:39pm UTC](https://discuss.elastic.co/t/using-painless-script-with-lucene-query-in-elasticsearch/150571/3 "2018-10-31T23:39:41Z")

</div>

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