org.elasticsearch.client
elasticsearch-rest-high-level-client
7.0.0
org.elasticsearch
elasticsearch
7.0.0
org.elasticsearch.client
transport
7.0.0
org.elasticsearch.plugin
transport-netty4-client
7.0.0
import org.elasticsearch.action.search.SearchResponse;
import java.util.List;
import java.util.Map;
/**
* @Author: gh
* @Description: elasticsearch ( )、 、 、 、 、 ;
* es , 。 。 。
*/
public interface EsDao {
/**
*
* @param index
* @param pageSize
* @param pageNum
* @return
*/
public SearchResponse getAllRowsBySearchAfter(String index, Integer pageSize, Integer pageNum);
public SearchResponse getAllRowsByFromSize(String index, Integer pageSize, Integer pageNum);
public List
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.genius.pojo.pg.dto.DataBaseDTO;
import com.genius.util.StringUtil;
import com.genius.util.common.FileSizeUtil;
import com.genius.util.common.SizeUnitEnum;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.elasticsearch.action.DocWriteRequest;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.*;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.*;
import org.elasticsearch.client.core.CountRequest;
import org.elasticsearch.client.core.CountResponse;
import org.elasticsearch.client.indices.*;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.geo.builders.CoordinatesBuilder;
import org.elasticsearch.common.geo.builders.GeometryCollectionBuilder;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.*;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.Scroll;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.locationtech.jts.geom.Coordinate;
import org.springframework.util.StringUtils;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Description: es JDBC ( )、 、 、 、 。
* 【 】
* 1.Elasticsearch JDBC ; 。
* 2. Elasticsearch x-pack-sql-jdbc :
* java.sql.SQLInvalidAuthorizationSpecException:
* current license is non-compliant for [jdbc]
* JDBC ,elasticsearch :https://www.elastic.co/cn/subscriptions
*/
public class EsDaoImpl implements EsDao{
RestHighLevelClient restClient = null;
DataBaseDTO dataBaseDTO = null;
public EsDaoImpl(DataBaseDTO dbd) {
try {
dataBaseDTO = dbd;
this.restClient = connectToES();
//initClient();
} catch (Exception e) {
e.printStackTrace();
}
}
public RestHighLevelClient getRestClient() {
return restClient;
}
public void setRestClient(RestHighLevelClient restClient) {
this.restClient = restClient;
}
/**
*
*/
public void close(){
try{
if(this.restClient != null){
restClient.close();
}
}catch(IOException e){
e.printStackTrace();
}
}
public boolean connected(){
try {
if(getRestClient() != null && getRestClient().ping(RequestOptions.DEFAULT)){
return true;
}
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
/**
* JDBC elasticsearch。http port=9200
* jdbc:es://[[http|https]://][host[:port]]/[prefix] 1){
String scrollId = resp.getScrollId();
for(int i=1;i> getAllRowsByScroll(String indexName, String column, String value) {
List
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.geo.GeoUtils;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import java.io.IOException;
import java.util.regex.Pattern;
/**
* @Description: elasticsearch :
* https://www.elastic.co/guide/en/elasticsearch/reference/6.0/mapping-types.html
* elasticsearch
*/
public enum EsFieldType {
/**
* , 。
* geo_point :
* # "location": {"lat": 41.12,"lon": -71.34}
* # "location": "41.12,-71.34"
* #geohash "location": "drm3btev3e86"
* # "location": [ -71.34, 41.12 ]
*/
GEO_POINT("geo_point"){
@Override
public Object fieldValueTransfer(String fieldValue) {
String rex1 = "\\{(\\s)*\"lat\"(\\s)*:(\\s)*(\\-|\\+)?\\d+(\\.\\d+)?(\\s)*,"+
"(\\s)*\"lon\"(\\s)*:(\\s)*(\\-|\\+)?\\d+(\\.\\d+)?(\\s)*\\}";
String rex2 = "(\\-|\\+)?\\d+(\\.\\d+)?(\\s)*,(\\s)*(\\-|\\+)?\\d+(\\.\\d+)?";
String rex3 = "^[a-z0-9]+$";
String rex4 = "^\\[(\\s)*(\\-|\\+)?\\d+(\\.\\d+)?(\\s)*,(\\s)*(\\-|\\+)?\\d+(\\.\\d+)?(\\s)*\\]$";
if(match(rex1,fieldValue)){
//json object
return parseJsonToGeopoint(fieldValue);
}else if(match(rex4,fieldValue)){
//array
return JSON.parseArray(fieldValue);
}else if(match(rex2,fieldValue)){
//string
return fieldValue;
}else if(match(rex3,fieldValue)){
//geohash,
return GeoPoint.fromGeohash(fieldValue);
}else{
return null;
}
}
private GeoPoint parseJsonToGeopoint(String jsonStr){
//{"lat": 41.12,"lon": -71.34}
JSONObject jo = JSON.parseObject(jsonStr);
// JSONObject , 。
return new GeoPoint(jo.getDoubleValue("lat"), jo.getDoubleValue("lon"));
}
};
EsFieldType(String type) {
this.type = type;
}
public Object getTransferedField(String fieldValue){
return fieldValueTransfer(fieldValue);
}
public boolean match(String rex,String input){
Pattern p = Pattern.compile(rex);
return p.matcher(input).matches();
}
private String type;
public String getType() {
return type;
}
protected abstract Object fieldValueTransfer(String fieldValue);
}