|  | @ -55,43 +55,54 @@ public class AdminServerAutoConfig {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @PostConstruct
 | 
	
		
			
				|  |  |     public void createIndex() throws Exception {
 | 
	
		
			
				|  |  |         Client client = elastricSearchHelper.getElasticsearchUtil().getElasticFactory();
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             Client client = elastricSearchHelper.getElasticsearchUtil().getElasticFactory();
 | 
	
		
			
				|  |  |             //判断index是否存在
 | 
	
		
			
				|  |  |             if (!client.prepareExists(adminServerProperties.getDefaultIndexName()).get().exists()) {
 | 
	
		
			
				|  |  |                 CreateIndexRequestBuilder cib = client.admin()
 | 
	
		
			
				|  |  |                         .indices().prepareCreate(adminServerProperties.getDefaultIndexName());
 | 
	
		
			
				|  |  |                 XContentBuilder mapping = XContentFactory.jsonBuilder()
 | 
	
		
			
				|  |  |                         .startObject()
 | 
	
		
			
				|  |  |                         .startObject("properties") //设置之定义字段
 | 
	
		
			
				|  |  |                         .startObject("uri")
 | 
	
		
			
				|  |  |                         .field("type", "string") //设置数据类型
 | 
	
		
			
				|  |  |                         .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
 | 
	
		
			
				|  |  |                         .endObject()
 | 
	
		
			
				|  |  |                         .startObject("spanname")
 | 
	
		
			
				|  |  |                         .field("type", "string")
 | 
	
		
			
				|  |  |                         .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
 | 
	
		
			
				|  |  |                         .endObject()
 | 
	
		
			
				|  |  |                         .startObject("ip")
 | 
	
		
			
				|  |  |                         .field("type", "string")
 | 
	
		
			
				|  |  |                         .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
 | 
	
		
			
				|  |  |                         .endObject()
 | 
	
		
			
				|  |  |                         .startObject("eventname")
 | 
	
		
			
				|  |  |                         .field("type", "string")
 | 
	
		
			
				|  |  |                         .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
 | 
	
		
			
				|  |  |                         .endObject()
 | 
	
		
			
				|  |  |                         .startObject("method")
 | 
	
		
			
				|  |  |                         .field("type", "string")
 | 
	
		
			
				|  |  |                         .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
 | 
	
		
			
				|  |  |                         .endObject()
 | 
	
		
			
				|  |  |                         .endObject()
 | 
	
		
			
				|  |  |                         .endObject();
 | 
	
		
			
				|  |  |                 cib.addMapping(adminServerProperties.getDefaultTypeName(), mapping);
 | 
	
		
			
				|  |  |                 CreateIndexResponse indexResponse = cib.execute().actionGet();
 | 
	
		
			
				|  |  |                 logger.info("自动创建索引");
 | 
	
		
			
				|  |  |             Boolean flag = client.prepareExists(adminServerProperties.getDefaultIndexName()).get().exists();
 | 
	
		
			
				|  |  |             if (!flag) {
 | 
	
		
			
				|  |  |                 createIndex(client);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         } catch (org.elasticsearch.index.IndexNotFoundException e) {
 | 
	
		
			
				|  |  |             createIndex(client);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             logger.error(e.getMessage());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private void createIndex(Client client) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             CreateIndexRequestBuilder cib = client.admin()
 | 
	
		
			
				|  |  |                     .indices().prepareCreate(adminServerProperties.getDefaultIndexName());
 | 
	
		
			
				|  |  |             XContentBuilder mapping = XContentFactory.jsonBuilder()
 | 
	
		
			
				|  |  |                     .startObject()
 | 
	
		
			
				|  |  |                     .startObject("properties") //设置之定义字段
 | 
	
		
			
				|  |  |                     .startObject("uri")
 | 
	
		
			
				|  |  |                     .field("type", "string") //设置数据类型
 | 
	
		
			
				|  |  |                     .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
 | 
	
		
			
				|  |  |                     .endObject()
 | 
	
		
			
				|  |  |                     .startObject("spanname")
 | 
	
		
			
				|  |  |                     .field("type", "string")
 | 
	
		
			
				|  |  |                     .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
 | 
	
		
			
				|  |  |                     .endObject()
 | 
	
		
			
				|  |  |                     .startObject("ip")
 | 
	
		
			
				|  |  |                     .field("type", "string")
 | 
	
		
			
				|  |  |                     .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
 | 
	
		
			
				|  |  |                     .endObject()
 | 
	
		
			
				|  |  |                     .startObject("eventname")
 | 
	
		
			
				|  |  |                     .field("type", "string")
 | 
	
		
			
				|  |  |                     .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
 | 
	
		
			
				|  |  |                     .endObject()
 | 
	
		
			
				|  |  |                     .startObject("method")
 | 
	
		
			
				|  |  |                     .field("type", "string")
 | 
	
		
			
				|  |  |                     .field("index", "not_analyzed") //设置数据类型	"index": "not_analyzed"
 | 
	
		
			
				|  |  |                     .endObject()
 | 
	
		
			
				|  |  |                     .endObject()
 | 
	
		
			
				|  |  |                     .endObject();
 | 
	
		
			
				|  |  |             cib.addMapping(adminServerProperties.getDefaultTypeName(), mapping);
 | 
	
		
			
				|  |  |             CreateIndexResponse indexResponse = cib.execute().actionGet();
 | 
	
		
			
				|  |  |             logger.info("自动创建索引");
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |             logger.error(e.getMessage());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |