|
@ -154,8 +154,7 @@ public class ElasticSearchHandler {
|
|
|
CreateIndexRequestBuilder cib = client.admin()
|
|
|
.indices().prepareCreate(index);
|
|
|
mapping = XContentFactory.jsonBuilder()
|
|
|
.startObject()
|
|
|
.startObject("properties"); //设置之定义字段
|
|
|
.startObject().startObject("properties"); //设置之定义字段
|
|
|
|
|
|
for(FieldInfo info : fieldInfoList){
|
|
|
String field = info.getField();
|
|
@ -167,37 +166,39 @@ public class ElasticSearchHandler {
|
|
|
Integer participle = info.getParticiple();
|
|
|
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();
|
|
|
mapping.startObject(field).field("type", "string").field("index", "not_analyzed").endObject();
|
|
|
}else if(participle == 2) {
|
|
|
mapping.startObject(field).field("type", "string").endObject();
|
|
|
}else {
|
|
|
mapping.startObject(field)
|
|
|
.field("type","keyword")
|
|
|
.field("index","not_analyzed")
|
|
|
.endObject();
|
|
|
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()
|
|
@ -226,39 +227,20 @@ public class ElasticSearchHandler {
|
|
|
.startObject()
|
|
|
.startObject("properties") //设置之定义字段
|
|
|
|
|
|
.startObject("id")//字段id
|
|
|
.field("type", "integer")//设置数据类型
|
|
|
.field("index", "not_analyzed")
|
|
|
|
|
|
.endObject()
|
|
|
.startObject("classs")
|
|
|
.field("type", "integer")
|
|
|
.field("index", "not_analyzed")
|
|
|
.endObject()
|
|
|
.startObject("id") .field("type", "integer").field("index", "not_analyzed").endObject()
|
|
|
.startObject("classs").field("type", "integer").field("index", "not_analyzed").endObject()
|
|
|
|
|
|
.startObject("score")
|
|
|
.field("type", "integer")
|
|
|
.field("index", "not_analyzed")
|
|
|
.endObject()
|
|
|
.startObject("score").field("type", "integer").field("index", "not_analyzed").endObject()
|
|
|
|
|
|
//子属性
|
|
|
.startObject("student")
|
|
|
.startObject("properties")
|
|
|
.startObject("name")
|
|
|
.field("type", "string")
|
|
|
.field("index", "not_analyzed")
|
|
|
.endObject()
|
|
|
|
|
|
.startObject("age")
|
|
|
.field("type", "string")
|
|
|
.endObject()
|
|
|
.startObject("name").field("type", "string").field("index", "not_analyzed").endObject()
|
|
|
.startObject("age").field("type", "string").endObject()
|
|
|
.endObject()
|
|
|
.endObject()
|
|
|
|
|
|
.startObject("updatetime")
|
|
|
.field("type","integer")
|
|
|
.field("index","not_analyzed")
|
|
|
.endObject()
|
|
|
.startObject("updatetime").field("type", "date").field("format", "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis").endObject()
|
|
|
|
|
|
.endObject()
|
|
|
.endObject();
|