Elasticsearch:在文档字段的值中获取子字符串? [英] Elasticsearch: get for a substring in the value of a document field?
问题描述
在 mysql
中,我可以使用 sql
SELECT LEFT(field,4)from table
来搜索字段的4个字节.>
Elasticsearch
有相似的语法吗?
借助ES,您可以使用 然后在您的响应中,您将获得一个名为 还要确保启用动态脚本以使其正常工作. In With ES, you can use In your case, this would translate to making a query like this: Then in your response you'll get a field named Also make sure to enable dynamic scripting in order for this to work. 这篇关于Elasticsearch:在文档字段的值中获取子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! left_field
的字段,其中将包含 field
值的最左边四个字符.mysql
I can use the sql
SELECT LEFT(field,4) from table
to search 4 bytes of a field.Elasticsearch
has similar grammar?script_fields
in order to perform any script computation on existing fields.{
"query" : {
"match_all": {}
},
"script_fields" : {
"left_field" : {
"script" : {
"inline": "doc.field.value.substring(0, length)"
"params": {
"length": 4
}
}
}
}
}
left_field
which will contain the 4 left-most characters of the field
value.