The following works in groovy but not in painless; any ideas what I'm doing wrong (using elasticsearch-dsl-py but that shouldn't matter)?:
.bucket('protocol', 'terms', script={
'inline': 'def protocol = doc["name"].value[0..4]; \
if (protocol == "https") { \
return "https"; \
} else if (protocol[0..3] == "http") { \
return "http"; \
} else { \
return "other"; \
}',
'lang': 'groovy'
}, size=100)
.bucket('protocol', 'terms', script={
'inline': 'def protocol = doc["name"].value.substring(0, 4); \
if (protocol == "https") { \
return "https"; \
} else if (protocol.substring(0, 3) == "http") { \
return "http"; \
} else { \
return "other"; \
}',
'lang': 'painless'
}, size=100)