elasticsearch - 如何在字符串字段长度和以“99”结尾的字段的条件下查询
问题描述
使用以下查询时出现错误:
GET trxdetail-fj/_search
{
"query": {
"script": {
"script": {
"source": "doc['OPPACC'].length()>10",
"lang": "painless"
}
}
}
}
错误信息:
{
"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "failed to create query: {\n "script" : {\n "script" : {\n "source" : "doc['OPPACC'].length()>10",\n "lang" : "painless"\n },\n "boost" : 1.0\n }\n}",
"index_uuid": "n1UUebJaT7WJiomMDjbCXw",
"index": "trxdetail-fj"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "trxdetail-fj",
"node": "KNkvY1LsSQ-VA61GpNNWkA",
"reason": {
"type": "query_shard_exception",
"reason": "failed to create query: {\n "script" : {\n "script" : {\n "source" : "doc['OPPACC'].length()>10",\n "lang" : "painless"\n },\n "boost" : 1.0\n }\n}",
"index_uuid": "n1UUebJaT7WJiomMDjbCXw",
"index": "trxdetail-fj",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "cannot execute scripts using [filter] context"
}
}
}
]
},
"status": 400
}
我的配置是:
# ---------------------------------- script -----------------------------------
script.allowed_types: inline
script.allowed_contexts: search,update,aggs
最后,我想在我的索引中搜索以“99”结尾且字段长度为 12 的记录。
例如,匹配条件的“oppacc”字段中的记录之一是“347897109899”。
怎么做 ?
解决方案
推荐阅读
- r - 如何在 R 包 tmap 中为专题图使用连续色标?
- r - R:有效地计算值子集的摘要,其内容由两个变量之间的关系决定
- windows - 使用一些变量删除带有通配符的文件夹
- mysql - 用于内部连接的 laravel 查询构建
- r - 为 cuzick 测试安装的软件包
- java - 测验应用 Android Studio 的评分逻辑存在问题
- python-3.x - Kivy 中的依赖循环视图
- android - 反应原生 - 无法暂停活动(java.util.ConcurrentModificationException)
- t4 - Devart T4 Editor 1.0.9 无法为 VS 2017 Pro 安装
- python - file.write 在 python 中自动追加一个新行