Created
May 4, 2017 02:57
elasticsearch query by string length
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"query": { | |
"bool": { | |
"must": { | |
"script": { | |
"script": { | |
"inline": "doc['被执行人姓名/名称.raw'].getValue().length() < 4 ", | |
"lang": "painless" | |
} | |
} | |
} | |
} | |
} | |
} |
That query is wrong!
Error: A document doesn't have a value for a field! Use doc[].size()==0 to check if a document is missing a field!
The correct query is:
{
"query": {
"bool": {
"must": {
"script": {
"script": {
"inline": "doc['被执行人姓名/名称.raw'].size() > 0 && doc['被执行人姓名/名称.raw'].value.length() < 4",
"lang": "painless"
}
}
}
}
}
}
am I only one that gets
oc['log_processed.request_id'].size() > 0 && doc['log_processed.request_id'].value.length() < 4
^---- HERE
error ?
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
i just gave it to translator :)
dont worry - it will be painless :)