In mysql
I can use the sql
SELECT LEFT(field,4) from table
to search 4 bytes of a field.
Elasticsearch
has similar grammar?
With ES, you can use script_fields
in order to perform any script computation on existing fields.
In your case, this would translate to making a query like this:
{
"query" : {
"match_all": {}
},
"script_fields" : {
"left_field" : {
"script" : {
"inline": "doc.field.value.substring(0, length)"
"params": {
"length": 4
}
}
}
}
}
Then in your response you'll get a field named left_field
which will contain the 4 left-most characters of the field
value.
Also make sure to enable dynamic scripting in order for this to work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.