V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
Aenlly
V2EX  ›  程序员

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

  •  
  •   Aenlly · 2022-09-25 18:29:56 +08:00 · 976 次点击
    这是一个创建于 815 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在聚合中添加脚本

    {"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
    }
    
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1014 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 22:21 · PVG 06:21 · LAX 14:21 · JFK 17:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.