求解,为何 es 脚本在超过 10 个文档后报出越界异常

2022-09-25 18:29:56 +08:00
 Aenlly

在聚合中添加脚本

{"aggs": {
        "gwAppName": {
            "terms": {
                "field": "field",
                "script": {
"source": "doc['field1'].empty?doc['field'].value:doc['field1'].value",
                           "lang": "painless"
                       }
                }
   		 }      
}

字段结构

field 与 field1 均为 keyword

field 保证绝对有值,field1 不一定有值

报错

在前 10 条数据时,聚合正常

在超过 10 条数据时异常报错

{
    "error": {
        "root_cause": [
            {
                "type": "script_exception",
                "reason": "runtime error",
                "script_stack": [
                    "java.nio.Buffer.checkIndex(Buffer.java:540)",
                    "java.nio.DirectByteBuffer.get(DirectByteBuffer.java:253)",
                    "org.apache.lucene.store.ByteBufferGuard.getByte(ByteBufferGuard.java:118)",
                    "org.apache.lucene.store.ByteBufferIndexInput$SingleBufferImpl.readByte(ByteBufferIndexInput.java:385)",
                    "org.apache.lucene.util.packed.DirectReader$DirectPackedReader2.get(DirectReader.java:106)",
                    "org.apache.lucene.codecs.lucene70.Lucene70DocValuesProducer$19.ordValue(Lucene70DocValuesProducer.java:865)",
                    "org.apache.lucene.index.SingletonSortedSetDocValues.advanceExact(SingletonSortedSetDocValues.java:83)",
                    "org.elasticsearch.index.fielddata.FieldData$10.advanceExact(FieldData.java:345)",
                    "org.elasticsearch.index.fielddata.ScriptDocValues$BinaryScriptDocValues.setNextDocId(ScriptDocValues.java:685)",
                    "org.elasticsearch.index.fielddata.ScriptDocValues$Strings.setNextDocId(ScriptDocValues.java:720)",
                    "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:94)",
                    "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:39)",
"doc['field1'].empty?doc['field'].value:doc['field1'].value",
"                                           ^---- HERE"
                ],
                "script": "doc['field1'].empty?doc['field'].value:doc['field1'].value",
                "lang": "painless"
            }
        ],
        "type": "search_phase_execution_exception",
        "reason": "all shards failed",
        "phase": "query",
        "grouped": true,
        "failed_shards": [
            {
                "shard": 0,
                "index": "log-lemon-agw-access-hexi-20220924",
                "node": "m6KEOrUgTMqRKvNpf1eEWw",
                "reason": {
                    "type": "script_exception",
                    "reason": "runtime error",
                    "script_stack": [
                        "java.nio.Buffer.checkIndex(Buffer.java:540)",
                        "java.nio.DirectByteBuffer.get(DirectByteBuffer.java:253)",
                        "org.apache.lucene.store.ByteBufferGuard.getByte(ByteBufferGuard.java:118)",
                        "org.apache.lucene.store.ByteBufferIndexInput$SingleBufferImpl.readByte(ByteBufferIndexInput.java:385)",
                        "org.apache.lucene.util.packed.DirectReader$DirectPackedReader2.get(DirectReader.java:106)",
                        "org.apache.lucene.codecs.lucene70.Lucene70DocValuesProducer$19.ordValue(Lucene70DocValuesProducer.java:865)",
                        "org.apache.lucene.index.SingletonSortedSetDocValues.advanceExact(SingletonSortedSetDocValues.java:83)",
                        "org.elasticsearch.index.fielddata.FieldData$10.advanceExact(FieldData.java:345)",
                        "org.elasticsearch.index.fielddata.ScriptDocValues$BinaryScriptDocValues.setNextDocId(ScriptDocValues.java:685)",
                        "org.elasticsearch.index.fielddata.ScriptDocValues$Strings.setNextDocId(ScriptDocValues.java:720)",
                        "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:94)",
                        "org.elasticsearch.search.lookup.LeafDocLookup.get(LeafDocLookup.java:39)",
"doc['field1'].empty?doc['field'].value:doc['field1'].value",
"                                           ^---- HERE"
                    ],
                    "script": "doc['field1'].empty?doc['field'].value:doc['field1'].value",
                    "lang": "painless",
                    "caused_by": {
                        "type": "index_out_of_bounds_exception",
                        "reason": null
                    }
                }
            }
        ]
    },
    "status": 500
}

950 次点击
所在节点    程序员
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/882831

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX