Home > OS >  How to check if the integer 0 is contained in an array Painless, ElasticSearch
How to check if the integer 0 is contained in an array Painless, ElasticSearch

Time:12-23

I'm new to the Painless scripting language and I believe that my problem is quite simple: one field in my data is an array of integers. I want to add a Runtime mapping which yields false if 0 is in the array and true if it is not. I tried the following:

PUT my_index/_mapping
{
  "runtime": {
    "success": {
      "type": "boolean",
      "script": {
        "source": "emit(doc['my_key'].contains(0))" }
    }
  }
}

The return is "false" every time, so I guess that I'm doing it wrong (I'm sure that not all of these array contain the 0).

Thanks for your help!

CodePudding user response:

Try this instead:

"source": "emit(doc['my_key'].indexOf(0L) >= 0)" }
  • Related