Navigation Menu

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 }
@robertlyson
Copy link

Very nice .. thanks!

@vmavromatis
Copy link

Awesome! Have a star :P

@wlbhiro
Copy link

wlbhiro commented Jan 8, 2019

+1

@erickertz
Copy link

+1 ty!

@hieudang-agilityio
Copy link

+1

@sor-barroso
Copy link

👍

@Ranakel
Copy link

Ranakel commented Jun 26, 2020

Great !

@chenslrv
Copy link

chenslrv commented Nov 5, 2020

Thanks!!

@stefnestor
Copy link

Thank you!

@alex-ip
Copy link

alex-ip commented Jan 31, 2021

Thanks! Exactly what I was after.

@pmwikya
Copy link

pmwikya commented Apr 26, 2021

+1

@dentropy
Copy link

An hour of googling has lead me here, this has solved my issue +1

@emmanuelvacher
Copy link

Thanks 🙏

@JakubPolcar
Copy link

Thanks!

@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