Skip to content

通过ES索引别名获取mapping,返回数据为真实索引,而不是别名,导致mappings.get(index).get(type)报空指针异常#4122

Merged
agapple merged 1 commit into
alibaba:masterfrom
xyz487:master
May 13, 2022

Conversation

@xyz487
Copy link
Copy Markdown
Contributor

@xyz487 xyz487 commented Mar 28, 2022

bug fix #4121 通过ES索引别名获取maping后mappings.get(index).get(type)空指针异常

问题复现:

  1. 当canal-es服务重启后,首次触发获取ES索引mapping:

程序位置:
类 ESConnection
方法 public MappingMetaData getMapping(String index, String type)
程序 response = RestHighLevelClientExt.getMapping(restHighLevelClient, request, RequestOptions.DEFAULT);

http://xxxxxx.elasticsearch.aliyuncs.com:9200/order_pos/_mappings,其中order_pos为别名,返回数据:
{
    "order_pos_2022.03-000011":{
        "mappings":{
            "_doc":{
                "properties":{
                    "createdTime":{
                        "type":"keyword",
                        "index":false
                    },
                    "customerId":{
                        "type":"long"
                    },
                    ......
                    "ver":{
                        "type":"integer",
                        "index":false
                    }
                }
            }
        }
    }
}

返回结果中索引名order_pos_2022.03-000011为真正的索引。
2. 当执行mappings.get(index).get(type)代码时,入参index为配置的别名order_pos,mappings.get(order_pos)返回null
3. 引起NullPointException异常

处理办法:
因为是写入数据,通过索引获取mapping只能有1个mapping数据,取到即可:

mappings.get(index)换成 mappings.valuesIt().next();

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 28, 2022

CLA assistant check
All committers have signed the CLA.

@xyz487 xyz487 changed the title 通过索引别名获取mapping,返回数据为真实索引,而不是别名,导致mappings.get(index).get(type)报空指针异常 通过ES索引别名获取mapping,返回数据为真实索引,而不是别名,导致mappings.get(index).get(type)报空指针异常 Mar 28, 2022
@agapple agapple merged commit e48bc35 into alibaba:master May 13, 2022
@agapple
Copy link
Copy Markdown
Member

agapple commented May 13, 2022

tks

@agapple agapple added this to the v1.1.6 milestone May 23, 2022
@yourse007
Copy link
Copy Markdown

es7的EsConnection是不是也要同步改一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

通过索引别名获取mapping,mappings.get(index).get(type)报空指针异常

4 participants