如何查询字符串字段的长度和以“ 99”结尾的字段

时间:2019-02-15 06:44:49

标签: elasticsearch

使用以下查询时出现错误:

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”,这与条件相符。

如何做到?

0 个答案:

没有答案