Script syntax help

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:

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:

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 :slight_smile:

thanks

&& should do

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

{
  "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

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