Browse Source

es mapping

jkzlzhoujie 6 years ago
parent
commit
539ae66998
1 changed files with 27 additions and 7 deletions
  1. 27 7
      src/main/java/com/yihu/quota/util/ElasticSearchHandler.java

+ 27 - 7
src/main/java/com/yihu/quota/util/ElasticSearchHandler.java

@ -167,18 +167,38 @@ public class ElasticSearchHandler {
                if("string".equals(dataType)){
                    if(participle == 1) {
                        mapping.startObject(field).field("type", "string").field("index", "not_analyzed").endObject();
                    }else if(participle == 2){
                        mapping.startObject(field).field("type", "text").field("analyzer", "ik_max_word").endObject();
                    }else if(participle == 3){
                        mapping.startObject(field).field("type", "text").field("analyzer", "ik_smart").endObject();
                    }else if(participle == 2) {
                        mapping.startObject(field).field("type", "string").endObject();
                    }else {
                        mapping.startObject(field).field("type", "keyword").field("index", "not_analyzed").endObject();
                    }
                }else if("date".equals(dataType)){
                    mapping.startObject(field).field("type", dataType).field("format", "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis")
                            .endObject();
                    mapping.startObject(field).field("type", dataType).field("format", "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis").endObject();
                }else if("nested".equals(dataType)){//子集属性
                    mapping.startObject(field).startObject("properties");
                    //子属性
                    List<FieldInfo> childFieldList = info.getFieldInfos();
                    for(FieldInfo child : childFieldList){
                        String childField = child.getField();
                        String childDataType = child.getDataType();
                        int childParticiple = child.getParticiple();
                        if("string".equals(childDataType)){
                            if(childParticiple == 1) {
                                mapping.startObject(childField).field("type", "string").field("index", "not_analyzed").endObject();
                            }else if(childParticiple == 2) {
                                mapping.startObject(childField).field("type", "string").endObject();
                            }else {
                                mapping.startObject(childField).field("type", "keyword").field("index", "not_analyzed").endObject();
                            }
                        }else if("date".equals(dataType)){
                            mapping.startObject(childField).field("type", childDataType).field("format", "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis").endObject();
                        }else {
                            mapping.startObject(childField) .field("type", childDataType).endObject();
                        }
                    }
                    mapping.endObject().endObject();
                }else {
                    mapping.startObject(field) .field("type", dataType).field("index", "not_analyzed").endObject();
                    mapping.startObject(field) .field("type", dataType).endObject();
                }
            }
            mapping.endObject()