Skip to content

Instantly share code, notes, and snippets.

@jclosure
Created July 3, 2017 05:33
Show Gist options
  • Star 39 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jclosure/8e103dee2f7e9491845a2c0bb64c6b7a to your computer and use it in GitHub Desktop.
Save jclosure/8e103dee2f7e9491845a2c0bb64c6b7a to your computer and use it in GitHub Desktop.
Kibana Painless scripted field checks if field exists or is empty and returns default, otherwise value
if (!doc.containsKey('myfield') || doc['myfield'].empty) { return "unavailable" } else { return doc['myfield'].value }
@tecnodur
Copy link

Thanks. !doc.containsKey is the secret.

@sibay
Copy link

sibay commented Sep 21, 2021

+1

@fbaligand
Copy link

+1

@shinux
Copy link

shinux commented Jan 18, 2023

cool code

@jtristan-pinc
Copy link

Thank you

@MaianaBt
Copy link

Thank you so much !!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment