|
|
@@ -16,6 +16,7 @@ import org.apache.http.HttpEntity;
|
|
|
import org.apache.http.entity.ContentType;
|
|
|
import org.apache.http.nio.entity.NStringEntity;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
+import org.elasticsearch.client.Request;
|
|
|
import org.elasticsearch.client.Response;
|
|
|
import org.elasticsearch.client.RestClient;
|
|
|
import org.slf4j.Logger;
|
|
|
@@ -28,6 +29,8 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.IOException;
|
|
|
+import java.net.URLDecoder;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
@@ -105,27 +108,27 @@ public class CustomerApiController {
|
|
|
//拼装查询条件
|
|
|
StringBuilder builder =new StringBuilder();
|
|
|
builder.append("{");
|
|
|
- builder.append("\"query\": {");//query开始
|
|
|
- builder.append("\"bool\": {");//boot开始
|
|
|
- builder.append("\"must\": [");//must开始
|
|
|
+ builder.append("\"query\":{");//query开始
|
|
|
+ builder.append("\"bool\":{");//boot开始
|
|
|
+ builder.append("\"must\":[");//must开始
|
|
|
if(StringUtils.isNotEmpty(gender)){
|
|
|
- builder.append("{\"prefix\": { \"gender\": "+gender+"}},");
|
|
|
+ builder.append("{\"prefix\":{\"gender\":"+gender+"}},");
|
|
|
}
|
|
|
if(StringUtils.isNotEmpty(NOVPolicy)){
|
|
|
- builder.append("{\"prefix\": { \"label25\": \""+NOVPolicy+"\"}},");
|
|
|
+ builder.append("{\"prefix\":{\"label25\":\""+NOVPolicy+"\"}},");
|
|
|
}
|
|
|
if(StringUtils.isNotEmpty(custclass)){
|
|
|
- builder.append("{\"term\": { \"custclass\": \""+custclass+"\"}},");
|
|
|
+ builder.append("{\"term\":{\"custclass\":\""+custclass+"\"}},");
|
|
|
}
|
|
|
if(StringUtils.isNotEmpty(sobirth)){
|
|
|
- builder.append("{\"wildcard\": { \"sobirth\": \"*"+sobirth+"*\"}},");//模糊匹配
|
|
|
+ builder.append("{\"wildcard\":{\"sobirth\":\"*"+sobirth+"*\"}},");//模糊匹配
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isNotEmpty(SCustID)){
|
|
|
- builder.append("{\"wildcard\": { \"custid\": \"*"+SCustID+"*\"}},");//模糊匹配
|
|
|
+ builder.append("{\"wildcard\":{\"custid\":\"*"+SCustID+"*\"}},");//模糊匹配
|
|
|
}
|
|
|
if(StringUtils.isNotEmpty(custtype)){
|
|
|
- builder.append("{\"prefix\": { \"custtype\": \""+custtype+"\"}},");
|
|
|
+ builder.append("{\"prefix\":{\"custtype\":\""+custtype+"\"}},");
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isNotEmpty(beginBirthDay) && StringUtils.isNotEmpty(endBirthDay)){
|
|
|
@@ -154,7 +157,7 @@ public class CustomerApiController {
|
|
|
|
|
|
if(StringUtils.isNotEmpty(education)){
|
|
|
String[] edus = education.split("&");
|
|
|
- builder.append("{\"terms\":{\"education\":[" );
|
|
|
+ builder.append("{\"terms\":{\"education\":[");
|
|
|
for (String edu:edus) {
|
|
|
builder.append("\""+edu+"\",");
|
|
|
}
|
|
|
@@ -163,7 +166,7 @@ public class CustomerApiController {
|
|
|
}
|
|
|
|
|
|
if(customerIds.size()>0){
|
|
|
- builder.append("{\"terms\":{\"_id\":[" );
|
|
|
+ builder.append("{\"terms\":{\"_id\":[");
|
|
|
for (String id:customerIds) {
|
|
|
builder.append("\""+id+"\",");
|
|
|
}
|
|
|
@@ -173,11 +176,11 @@ public class CustomerApiController {
|
|
|
|
|
|
|
|
|
if(StringUtils.isNotEmpty(gzgw)){
|
|
|
- builder.append("{\"prefix\": { \"label73\": \"关注官微\"}},");
|
|
|
+ builder.append("{\"prefix\":{\"label73\":\"关注官微\"}},");
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isNotEmpty(zcgw)){
|
|
|
- builder.append("{\"prefix\": { \"label74\": \"注册官微\"}},");
|
|
|
+ builder.append("{\"prefix\":{\"label74\":\"注册官微\"}},");
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -190,19 +193,22 @@ public class CustomerApiController {
|
|
|
}
|
|
|
|
|
|
builder.append("],");//must结束
|
|
|
- builder.append("\"must_not\": [ ],");//must_not
|
|
|
- builder.append("\"should\": [ ]");//should
|
|
|
+ builder.append("\"must_not\":[],");//must_not
|
|
|
+ builder.append("\"should\":[]");//should
|
|
|
builder.append("}");//boot结束
|
|
|
builder.append("},");//query结束
|
|
|
- builder.append("\"from\": "+(pageNum*10+1)+",");//第几页
|
|
|
- builder.append("\"size\": "+pageSize+",");//查询几个
|
|
|
- builder.append(" \"sort\": [{\"created_time\":{\"order\":\"desc\"}}],");//排序
|
|
|
- builder.append(" \"aggs\": {}");//
|
|
|
+ builder.append("\"from\":"+(pageNum*10+1)+",");//第几页
|
|
|
+ builder.append("\"size\":"+pageSize+",");//查询几个
|
|
|
+ builder.append("\"sort\":[{\"created_time\":{\"order\":\"desc\"}}],");//排序
|
|
|
+ builder.append("\"aggs\":{}");//
|
|
|
builder.append("}");
|
|
|
|
|
|
HttpEntity entity = new NStringEntity(builder.toString(), ContentType.APPLICATION_JSON);
|
|
|
|
|
|
- Response response= restClient.performRequest("GET", "/shanglifeecif.individual/_search",Collections.<String, String>emptyMap(),entity);
|
|
|
+ Request scriptRequest = new Request("GET", "/shanglifeecif.individual/_search?q="+ URLEncoder.encode("\""+builder.toString()+"\""));
|
|
|
+// Request scriptRequest = new Request("GET", "/shanglifeecif.individual/_search?q=%22{%22query%22:{%22bool%22:{%22must%22:[],%22must_not%22:[],%22should%22:[]}},%22from%22:11,%22size%22:10,%22sort%22:[{%22created_time%22:{%22order%22:%22desc%22}}],%22aggs%22:{}}%22");
|
|
|
+ Response response = restClient.performRequest(scriptRequest);
|
|
|
+// Response response= restClient.performRequest("GET", "/shanglifeecif.individual/_search",Collections.<String, String>emptyMap(),entity);
|
|
|
|
|
|
String result = EntityUtils.toString(response.getEntity());
|
|
|
JSONObject jsonObject = JSON.parseObject(result);
|
|
|
@@ -304,7 +310,10 @@ public class CustomerApiController {
|
|
|
|
|
|
HttpEntity entity = new NStringEntity(builder.toString(), ContentType.APPLICATION_JSON);
|
|
|
|
|
|
- Response response= restClient.performRequest("GET", "/shanglifeecif.insurancearrangement/_search?scroll=1m",Collections.<String, String>emptyMap(),entity);
|
|
|
+ Request scriptRequest = new Request("GET", "/shanglifeecif.insurancearrangement/_search?scroll=1m&q="+ URLEncoder.encode("\""+builder.toString()+"\""));
|
|
|
+
|
|
|
+ Response response = restClient.performRequest(scriptRequest);
|
|
|
+// Response response= restClient.performRequest("GET", "/shanglifeecif.insurancearrangement/_search?scroll=1m",Collections.<String, String>emptyMap(),entity);
|
|
|
|
|
|
String result = EntityUtils.toString(response.getEntity());
|
|
|
JSONObject jsonObject = JSON.parseObject(result);
|
|
|
@@ -328,7 +337,10 @@ public class CustomerApiController {
|
|
|
}
|
|
|
// 继续向后查询
|
|
|
/* entity = new NStringEntity(JSONUtil.toJsonStr(obj), ContentType.APPLICATION_JSON);
|
|
|
- response= restClient.performRequest("GET", "/_search/scroll",Collections.<String, String>emptyMap(),entity);
|
|
|
+ Request scriptRequest = new Request("GET", "/_search/scroll?);
|
|
|
+
|
|
|
+ Response response = restClient.performRequest(scriptRequest);
|
|
|
+// response= restClient.performRequest("GET", "/_search/scroll",Collections.<String, String>emptyMap(),entity);
|
|
|
result = EntityUtils.toString(response.getEntity());
|
|
|
jsonObject = JSON.parseObject(result);
|
|
|
hitsobject = (JSONObject) jsonObject.get("hits");
|
|
|
@@ -346,7 +358,10 @@ public class CustomerApiController {
|
|
|
|
|
|
Map<String, String> paramMap = new HashMap<String, String>();
|
|
|
paramMap.put("pretty", "true");
|
|
|
- Response response = restClient.performRequest("GET", "/shanglifeecif.individual/default_type_/"+id, paramMap);
|
|
|
+ Request scriptRequest = new Request("GET", "/shanglifeecif.individual/default_type_/"+id+"?pretty=true");
|
|
|
+
|
|
|
+ Response response = restClient.performRequest(scriptRequest);
|
|
|
+// Response response = restClient.performRequest("GET", "/shanglifeecif.individual/default_type_/"+id, paramMap);
|
|
|
String result = EntityUtils.toString(response.getEntity());
|
|
|
Map map = new HashMap();
|
|
|
JSONObject jsonObject = JSON.parseObject(result);
|
|
|
@@ -371,7 +386,10 @@ public class CustomerApiController {
|
|
|
Map query =new HashMap();
|
|
|
query.put("indid1",indid);
|
|
|
HttpEntity entity = new NStringEntity(EsJsonUtil.QuerygetMust(query), ContentType.APPLICATION_JSON);
|
|
|
- response= restClient.performRequest("GET", "/shanglifeecif.indrelationship/_search",Collections.<String, String>emptyMap(),entity);
|
|
|
+ scriptRequest = new Request("GET", "/shanglifeecif.indrelationship/_search?pretty=true&q=indid1:"+indid);
|
|
|
+
|
|
|
+ response = restClient.performRequest(scriptRequest);
|
|
|
+// response= restClient.performRequest("GET", "/shanglifeecif.indrelationship/_search",Collections.<String, String>emptyMap(),entity);
|
|
|
result = EntityUtils.toString(response.getEntity());
|
|
|
jsonObject = JSON.parseObject(result);
|
|
|
JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
|
|
|
@@ -388,7 +406,10 @@ public class CustomerApiController {
|
|
|
query =new HashMap();
|
|
|
query.put("applicantid",indid);
|
|
|
entity = new NStringEntity(EsJsonUtil.QuerygetMust(query), ContentType.APPLICATION_JSON);
|
|
|
- response= restClient.performRequest("GET", "/shanglifeecif.insuranceclaimthread/_search",Collections.<String, String>emptyMap(),entity);
|
|
|
+ scriptRequest = new Request("GET", "/shanglifeecif.insuranceclaimthread/_search?pretty=true&q=applicantid:"+indid);
|
|
|
+
|
|
|
+ response = restClient.performRequest(scriptRequest);
|
|
|
+// response= restClient.performRequest("GET", "/shanglifeecif.insuranceclaimthread/_search",Collections.<String, String>emptyMap(),entity);
|
|
|
result = EntityUtils.toString(response.getEntity());
|
|
|
jsonObject = JSON.parseObject(result);
|
|
|
hitsobject = (JSONObject) jsonObject.get("hits");
|
|
|
@@ -406,7 +427,10 @@ public class CustomerApiController {
|
|
|
query =new HashMap();
|
|
|
query.put("applicantid",indid);
|
|
|
entity = new NStringEntity(EsJsonUtil.QuerygetMust(query), ContentType.APPLICATION_JSON);
|
|
|
- response= restClient.performRequest("GET", "/shanglifeecif.insurancearrangement/_search",Collections.<String, String>emptyMap(),entity);
|
|
|
+ scriptRequest = new Request("GET", "/shanglifeecif.insurancearrangement/_search?pretty=true&q=applicantid:"+indid);
|
|
|
+
|
|
|
+ response = restClient.performRequest(scriptRequest);
|
|
|
+// response= restClient.performRequest("GET", "/shanglifeecif.insurancearrangement/_search",Collections.<String, String>emptyMap(),entity);
|
|
|
result = EntityUtils.toString(response.getEntity());
|
|
|
jsonObject = JSON.parseObject(result);
|
|
|
hitsobject = (JSONObject) jsonObject.get("hits");
|
|
|
@@ -440,7 +464,10 @@ public class CustomerApiController {
|
|
|
try {
|
|
|
Map<String, String> paramMap = new HashMap<String, String>();
|
|
|
paramMap.put("pretty", "true");
|
|
|
- Response response = restClient.performRequest("GET", "shanglifeecif.individual/default_type_/"+id, paramMap);
|
|
|
+ Request scriptRequest = new Request("GET", "shanglifeecif.individual/default_type_/"+id+"?pretty=true");
|
|
|
+
|
|
|
+ Response response = restClient.performRequest(scriptRequest);
|
|
|
+// Response response = restClient.performRequest("GET", "shanglifeecif.individual/default_type_/"+id, paramMap);
|
|
|
String result = EntityUtils.toString(response.getEntity());
|
|
|
Map map = new HashMap();
|
|
|
JSONObject jsonObject = JSON.parseObject(result);
|
|
|
@@ -460,7 +487,10 @@ public class CustomerApiController {
|
|
|
Map query =new HashMap();
|
|
|
query.put("applicantid",indid);
|
|
|
HttpEntity entity = new NStringEntity(EsJsonUtil.QuerygetMust(query), ContentType.APPLICATION_JSON);
|
|
|
- response= restClient.performRequest("GET", "/shanglifeecif.insurancearrangement/_search",Collections.<String, String>emptyMap(),entity);
|
|
|
+ scriptRequest = new Request("GET", "/shanglifeecif.insurancearrangement/_search?pretty=true&q=applicantid:"+indid);
|
|
|
+
|
|
|
+ response = restClient.performRequest(scriptRequest);
|
|
|
+// response= restClient.performRequest("GET", "/shanglifeecif.insurancearrangement/_search",Collections.<String, String>emptyMap(),entity);
|
|
|
result = EntityUtils.toString(response.getEntity());
|
|
|
jsonObject = JSON.parseObject(result);
|
|
|
JSONObject hitsobject = (JSONObject) jsonObject.get("hits");
|
|
|
@@ -504,7 +534,10 @@ public class CustomerApiController {
|
|
|
query =new HashMap();
|
|
|
query.put("applicantid",indid);
|
|
|
entity = new NStringEntity(EsJsonUtil.QuerygetMust(query), ContentType.APPLICATION_JSON);
|
|
|
- response= restClient.performRequest("GET", "/shanglifeecif.insuranceclaimthread/_search",Collections.<String, String>emptyMap(),entity);
|
|
|
+ scriptRequest = new Request("GET", "/shanglifeecif.insuranceclaimthread/_search?pretty=true&q=applicantid:"+indid);
|
|
|
+
|
|
|
+ response = restClient.performRequest(scriptRequest);
|
|
|
+// response= restClient.performRequest("GET", "/shanglifeecif.insuranceclaimthread/_search",Collections.<String, String>emptyMap(),entity);
|
|
|
result = EntityUtils.toString(response.getEntity());
|
|
|
jsonObject = JSON.parseObject(result);
|
|
|
hitsobject = (JSONObject) jsonObject.get("hits");
|