Skip to content

Instantly share code, notes, and snippets.

@dushujun
Created May 4, 2017 02:57
Show Gist options
  • Save dushujun/ffd604c3dfea7c277505e721b3447e2d to your computer and use it in GitHub Desktop.
Save dushujun/ffd604c3dfea7c277505e721b3447e2d to your computer and use it in GitHub Desktop.
elasticsearch query by string length
{
"query": {
"bool": {
"must": {
"script": {
"script": {
"inline": "doc['被执行人姓名/名称.raw'].getValue().length() < 4 ",
"lang": "painless"
}
}
}
}
}
}
@amir2b
Copy link

amir2b commented Jul 1, 2023

am I only one that gets

oc['log_processed.request_id'].size() > 0 && doc['log_processed.request_id'].value.length() < 4
    ^---- HERE
    

error ?

If a record dose not have the log_processed field, it will gave you this error.
I think the correct query is:

doc['log_processed'] != null && doc['log_processed.request_id'].size() > 0 && doc['log_processed.request_id'].value.length() < 4

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