|
@ -4,6 +4,10 @@ package com.yihu.quota.util;
|
|
|
import com.yihu.quota.model.rest.FieldInfo;
|
|
|
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
|
|
|
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
|
|
|
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
|
|
|
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
|
|
|
import org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest;
|
|
|
import org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse;
|
|
|
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
|
|
|
import org.elasticsearch.client.Requests;
|
|
|
import org.elasticsearch.client.transport.TransportClient;
|
|
@ -101,6 +105,29 @@ public class ElasticSearchHandler {
|
|
|
client.admin().indices().create(request);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断指定的索引名是否存在
|
|
|
* @param indexName 索引名
|
|
|
* @return 存在:true; 不存在:false;
|
|
|
*/
|
|
|
public boolean isExistsIndex(String indexName,TransportClient client){
|
|
|
IndicesExistsResponse response = client.admin().indices().exists(
|
|
|
new IndicesExistsRequest().indices(new String[]{indexName})).actionGet();
|
|
|
return response.isExists();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断指定的索引的类型是否存在
|
|
|
* @param indexName 索引名
|
|
|
* @param indexType 索引类型
|
|
|
* @return 存在:true; 不存在:false;
|
|
|
*/
|
|
|
public boolean isExistsType(String indexName,String indexType,TransportClient client){
|
|
|
TypesExistsResponse response = client.admin().indices()
|
|
|
.typesExists(new TypesExistsRequest(new String[]{indexName}, indexType)).actionGet();
|
|
|
return response.isExists();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 创建mapping
|
|
|
* @param index 索引
|
|
@ -210,8 +237,8 @@ public class ElasticSearchHandler {
|
|
|
.endObject()
|
|
|
|
|
|
.startObject("score")
|
|
|
.field("type","integer")
|
|
|
.field("index","not_analyzed")
|
|
|
.field("type", "integer")
|
|
|
.field("index", "not_analyzed")
|
|
|
.endObject()
|
|
|
|
|
|
//子属性
|
|
@ -223,7 +250,7 @@ public class ElasticSearchHandler {
|
|
|
.endObject()
|
|
|
|
|
|
.startObject("age")
|
|
|
.field("type","string")
|
|
|
.field("type", "string")
|
|
|
.endObject()
|
|
|
.endObject()
|
|
|
.endObject()
|