首页 > 解决方案 > 如何在字符串字段长度和以“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”。

怎么做 ?

标签: elasticsearch

解决方案


推荐阅读