Skip to content

Instantly share code, notes, and snippets.

@benwtrent
Last active February 26, 2020 17:32
Show Gist options
  • Save benwtrent/87231cd159c437830d6f2d5bfec76280 to your computer and use it in GitHub Desktop.
Save benwtrent/87231cd159c437830d6f2d5bfec76280 to your computer and use it in GitHub Desktop.
Trying to recreate wierd script bug
PUT programs
{
"mappings": {
"properties": {
"visit_times" : {
"type" : "date",
"null_value" : "0"
}
}
}
}
POST programs/_doc
{
"no_visitts": 1
}
POST programs/_doc
{
"visit_times": null
}
POST programs/_doc
{
"visit_times": []
}
POST programs/_doc
{
"visit_times": 1582588800001
}
POST programs/_doc
{
"visit_times": [1582588800001, 1572588800001]
}
POST programs/_doc
{
"visit_times": [1482588800001, 1572588800001]
}
POST programs/_doc
{
"visit_times": 1482588800001
}
# Post a couple of these...
POST programs/_doc
{
"visit_times": [1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001,
1582588800001]
}
#Both searches are "worst case" as they look for values that are never in the range. So, it iterates ALL values.
# SLOW
POST /programs/_search
{
"query": {
"bool": {
"must": [
{
"script": {
"script": {
"lang": "painless",
"source": """
for (int i = 0; i < doc['visit_times'].length; ++i) {
long milliseconds = doc['visit_times'][i].toInstant().toEpochMilli();
if (milliseconds >= 1882588800000L && milliseconds <= 1882675199999L))
{
return true;
}
}
return false;
"""
}
}
}
]
}
}
}
#FAST!
POST /programs/_search
{
"query": {
"bool": {
"must": [
{
"script": {
"script": {
"lang": "painless",
"source": """
for (visit_time in doc['visit_times']) {
long milliseconds = visit_time.toInstant().toEpochMilli();
if (milliseconds >= 1882588800000L && milliseconds <= 1882675199999L))
{
return true;
}
}
return false;
"""
}
}
}
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment