# Script syntax help

**URL:** <https://discuss.elastic.co/t/script-syntax-help/282855>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [August 30, 2021, 9:41pm UTC](https://discuss.elastic.co/t/script-syntax-help/282855 "2021-08-30T21:41:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vester](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vester/32/81160_2.png) [@Vester](https://discuss.elastic.co/u/Vester)\
**Post date:** [August 30, 2021, 9:41pm UTC](https://discuss.elastic.co/t/script-syntax-help/282855/1 "2021-08-30T21:41:43Z")

</div>

Hi,

I'm trying to run a script query to get all docs with a boolean AND condition and I could not found and examples on how to do this. I have this script working:

```auto
GET indexX/_search?size=1000
{
    "query": {
        "bool": {
            "must": [{
                "script": {
                    "script": """ 
                    doc['field1.keyword'].value == doc['field1.keyword'].value
                    """
                }
            }
            ]
        }
    }
}type or paste code here

```

I would like to add a Boolean AND, something like this:

```auto
GET indexX/_search?size=1000
{
    "query": {
        "bool": {
            "must": [{
                "script": {
                    "script": """ 
                    doc['field1.keyword'].value == doc['field1.keyword'].value *AND 
                    doc['fieldB.keyword'].value != doc['fieldB.keyword'].value*
                    """
                }
            }
            ]
        }
    }
}
type or paste code here

```

can someone help with the right syntax 🙂

thanks

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [August 30, 2021, 10:03pm UTC](https://discuss.elastic.co/t/script-syntax-help/282855/2 "2021-08-30T22:03:36Z")

</div>

`&&` should do

---

<div class="post-metadata">

**Author:** ![Vester](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vester/32/81160_2.png) [@Vester](https://discuss.elastic.co/u/Vester)\
**Post date:** [August 31, 2021, 8:32am UTC](https://discuss.elastic.co/t/script-syntax-help/282855/3 "2021-08-31T08:32:42Z")

</div>

HI, thanks for the reply but I had already tried 🙂 no luck:

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "runtime error",
        "script_stack": [
          "org.elasticsearch.index.fielddata.ScriptDocValues$Strings.get(ScriptDocValues.java:496)",
          "org.elasticsearch.index.fielddata.ScriptDocValues$Strings.getValue(ScriptDocValues.java:503)",
          "doc['field1.keyword'].value == doc['field1.keyword'].value && doc['fieldB.keyword'].value == doc['fieldB.keyword'].value\r\n ",
          " ^---- HERE"
        ],
        "script": " \r\n doc['field1.keyword'].value == doc['field1.keyword'].value && doc['fieldB.keyword'].value == doc['fieldB.keyword'].value\r\n ",
        "lang": "painless"
      }
    ],

```

I'm really stuck, any help ?

thanks

---

<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:** [September 28, 2021, 8:33am UTC](https://discuss.elastic.co/t/script-syntax-help/282855/4 "2021-09-28T08:33:14Z")

</div>

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