ES--身份证判断性别

Posted 喜欢雨天的我

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ES--身份证判断性别相关的知识,希望对你有一定的参考价值。

身份证性别是身份证号的第17位,奇数为男 偶数为女

ES脚本

  int type = params.sexType;
                                boolean isStart = params.isStart;
                                if(!isStart)
                                    return true;
                                
                                String keys =  doc['keys'].value;
                                if(keys.length() != 18)
                                    return true;
                                String sexId =keys.substring(16, 17);
                                int number = Integer.parseInt(sexId);
                                int result = number % 2;
                                if(type == 1 && result != 0)
                                    return true;
                                else if(type == 0 && result == 0)
                                    return true;
                                
                                return false;

以上是关于ES--身份证判断性别的主要内容,如果未能解决你的问题,请参考以下文章