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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With