solr api:
private org.apache.solr.client.solrj.impl.HttpSolrServer solrServer92;
private org.apache.solr.client.solrj.impl.HttpSolrServer solrServer96;
Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
//构建刷solr数据
SolrInputDocument doc = buildSolrInputDocument(vdl, venderInfoDTO);
docs.add(doc);
try {
solrServer92.add(docs);
solrServer92.commit();
} catch (Exception e) {
log.error("批量同步所有mysql数据到92solr服务器-刷新全部solr数据遇到错误", e);
}
private SolrInputDocument buildSolrInputDocument(VenderAuthResultData vdl, VenderInfoDTO venderInfoDTO) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", (vdl.getVenderId() + "" + vdl.getOpTime()));
doc.addField("venderId", vdl.getVenderId());
doc.addField("checkPass", vdl.getCheckPass());
doc.addField("authPass", vdl.getAuthPass());
doc.addField("servicePass", vdl.getServicePass());
doc.addField("efficiencyPass", vdl.getEfficiencyPass());
doc.addField("authStatus", vdl.getAuthStatus());
doc.addField("serviceRank", vdl.getServiceRank() == null ? 0.0 : vdl.getServiceRank());
doc.addField("efficiencyRank", vdl.getEfficiencyRank() == null ? 0.0 : vdl.getEfficiencyRank());
doc.addField("serviceAvg", vdl.getServiceAvg() == null ? 0.0 : vdl.getServiceAvg());
doc.addField("efficiencyAvg", vdl.getEfficiencyAvg() == null ? 0.0 : vdl.getEfficiencyAvg());
doc.addField("basePass", vdl.getBasePass());
doc.addField("reportUrl", vdl.getReportUrl());
doc.addField("opTime", vdl.getOpTime());
doc.addField("venderName", venderInfoDTO.getVenderName() == null ? " " : venderInfoDTO.getVenderName());
doc.addField("shopName", venderInfoDTO.getShopName() == null ? " " : venderInfoDTO.getShopName());
doc.addField("operatorErpId", (venderInfoDTO.getOperatorErpId() != null && !venderInfoDTO.getOperatorErpId().equals("") ? venderInfoDTO.getOperatorErpId() : " "));
doc.addField("operatorName", venderInfoDTO.getOperatorName());
doc.addField("firstClassDeptId", venderInfoDTO.getFirstClassDeptId());
doc.addField("firstClassDeptName", venderInfoDTO.getFirstClassDeptName());
doc.addField("secondClassDeptId", venderInfoDTO.getSecondClassDeptId());
doc.addField("secondClassDeptName", venderInfoDTO.getSecondClassDeptName());
doc.addField("thirdClassDeptId", venderInfoDTO.getThirdClassDeptId());
doc.addField("thirdClassDeptName", venderInfoDTO.getThirdClassDeptName());
return doc;
}
<bean id="solrServer92" class="org.apache.solr.client.solrj.impl.HttpSolrServer">
<constructor-arg value="${solr.refresh.data.servers1}" />
<property name="connectionTimeout" value="5000" />
<property name="defaultMaxConnectionsPerHost" value="250" />
<property name="maxTotalConnections" value="2000" />
</bean>
Thread:
new Thread(new SolrDataHandleThread()).start();
new Thread(new ElasticSearchDataHandler()).start();
private class SolrDataHandleThread implements Runnable {
public void run() {
log.info("in SolrDataHandleThread run()--->begin");
log.info("pageSize is--->" + pageSize);
//调saf接口 根据商家id查询商家管理系统oracle数据 如商家的所属运营人员及部门的数据
List<VenderAuthResultData> resultDataAllList = venderAuthResultDataDao.getAllVenderAuthResultData();
log.info("in SolrDataHandleThread run()--->end");
}
}
/**
* 删除所有文档,为安全起见,使用时再解注函数体 。
*/
/*
public void deleteAll() {
log.info("solr删除所有文档--->开始");
try {
solrServerSingle.deleteByQuery("*:*");
solrServerSingle.commit();
} catch (Exception e) {
log.error("从solr删除所有文档时遇到错误", e);
}
log.info("solr删除所有文档--->结束");
}
*/
private List<SellerAuthDocument> searchSellerAuthDataList(SellerAuthDataQuery sellerAuthDataQuery, int pageNo, int pageSize) throws Exception {
/*
PaginatedList<SellerAuthDataVO> searchLists = new PaginatedArrayList<SellerAuthDataVO>(pageNo, pageSize);
List<SellerAuthDataVO> sellerAuthDataVOList=new ArrayList<SellerAuthDataVO>();
SolrQuery sQuery = new SolrQuery();
*/
List<SellerAuthDocument> searchListsGundog = null;
String para = buildSolrQueryParam(sellerAuthDataQuery);
// 查询关键词,*:*代表所有属性、所有值,即所有index
if(!StringUtils.isNotEmpty(para)){
para="*:*";
}
log.info("para:"+para);
/*
sQuery.setQuery(para);
//设置分页 start=0就是从0开始,,rows=5当前返回5条记录,第二页就是变化start这个值为5就可以了。
sQuery.setStart((pageNo-1)*pageSize);
sQuery.setRows(pageSize);
//排序 如果按照blogId 排序,,那么将blogId desc(or asc) 改成 id desc(or asc)
sQuery.addSortField("opTime", SolrQuery.ORDER.desc);
*/
try {
GundogQuery gundogQuery = new GundogQuery();
gundogQuery.setQuery(para);
//设置分页 start=0就是从0开始,,rows=5当前返回5条记录,第二页就是变化start这个值为5就可以了。
gundogQuery.setStart((pageNo-1)*pageSize);
gundogQuery.setRows(pageSize);
//排序 如果按照blogId 排序,,那么将blogId desc(or asc) 改成 id desc(or asc)
gundogQuery.addSortField("opTime", SolrQuery.ORDER.desc);
searchListsGundog = gundogServer.search(gundogQuery, WebHelper.getPin());
/*
QueryResponse response = solrServer.query(sQuery);
QueryResponse response = solrServerSingle.query(sQuery);
SolrDocumentList list = response.getResults();
Integer counts=(int) list.getNumFound();
log.info("counts:"+counts);
for (SolrDocument solrDocument : list) {
SellerAuthDataVO sellerAuthDataVO = buildSellerAuthDataVO(solrDocument);
sellerAuthDataVOList.add(sellerAuthDataVO);
}
searchLists.setIndex(pageNo);
searchLists.setPageSize(pageSize);
searchLists.setTotalItem(counts);
searchLists.addAll(sellerAuthDataVOList);
*/
} catch (Exception e) {
log.error("卖家服务认证MAN端查询出错",e);
}
return searchListsGundog;
}
/*
* 构建Solr查询参数
*/
private String buildSolrQueryParam(SellerAuthDataQuery sellerAuthDataQuery) {
String para = "";
if (sellerAuthDataQuery.getVenderId() != null && sellerAuthDataQuery.getVenderId() != 0) {
if(StringUtils.isNotEmpty(para)){
para=para+" AND venderId:"+ sellerAuthDataQuery.getVenderId();
}else{
para=para+" venderId:"+ sellerAuthDataQuery.getVenderId();
}
}
if (StringUtils.isNotEmpty(sellerAuthDataQuery.getVenderName())) {
if(StringUtils.isNotEmpty(para)){
para=para+" AND venderName:"+ sellerAuthDataQuery.getVenderName();
}else{
para=para+" venderName:"+ sellerAuthDataQuery.getVenderName();
}
}
if (StringUtils.isNotEmpty(sellerAuthDataQuery.getOpTime())) {
if(StringUtils.isNotEmpty(para)){
para=para+" AND opTime:"+ sellerAuthDataQuery.getOpTime();
}else{
para=para+" opTime:"+ sellerAuthDataQuery.getOpTime();
}
}
if (StringUtils.isNotEmpty(sellerAuthDataQuery.getShopName())) {
if(StringUtils.isNotEmpty(para)){
para=para+" AND shopName:"+ sellerAuthDataQuery.getShopName();
}else{
para=para+" shopName:"+ sellerAuthDataQuery.getShopName();
}
}
if (sellerAuthDataQuery.getCheckPass() != null) {
if(StringUtils.isNotEmpty(para)){
para=para+" AND checkPass:"+ sellerAuthDataQuery.getCheckPass();
}else{
para=para+" checkPass:"+ sellerAuthDataQuery.getCheckPass();
}
}
if (sellerAuthDataQuery.getAuthPass() != null) {
if(StringUtils.isNotEmpty(para)){
para=para+" AND authPass:"+ sellerAuthDataQuery.getAuthPass();
}else{
para=para+" authPass:"+ sellerAuthDataQuery.getAuthPass();
}
}
if (sellerAuthDataQuery.getAuthStatus() != null) {
if(StringUtils.isNotEmpty(para)){
para=para+" AND authStatus:"+ sellerAuthDataQuery.getAuthStatus();
}else{
para=para+" authStatus:"+ sellerAuthDataQuery.getAuthStatus();
}
}
//当前登陆运营人员ERP
if(StringUtils.isNotEmpty(sellerAuthDataQuery.getOperatorErpId())){
// 查询条件选择有部门-三级联动
if (StringUtils.isNotEmpty(sellerAuthDataQuery.getDeptIds())) {
String deptIds = sellerAuthDataQuery.getDeptIds();
String[] deptIdsArr = deptIds.split(",");
//部门仅选择了一级 则一级索引查询
if (deptIdsArr.length == 1) {
if(StringUtils.isNotEmpty(para)) {
para=para+" AND firstClassDeptId:"+ deptIdsArr[0];
}else{
para=para+" firstClassDeptId:"+ deptIdsArr[0];
}
// 部门选择了一级、二级 则一级、二级索引查询
} else if (deptIdsArr.length == 2) {
if(StringUtils.isNotEmpty(para)) {
para=para+" AND firstClassDeptId:"+ deptIdsArr[0];
}else{
para=para+" firstClassDeptId:"+ deptIdsArr[0];
}
if(StringUtils.isNotEmpty(para)) {
para=para+" AND secondClassDeptId:"+ deptIdsArr[1];
}else{
para=para+" secondClassDeptId:"+ deptIdsArr[1];
}
// 部门选择了一级、二级、三级, 则一级、二级、三级索引查询
} else if (deptIdsArr.length == 3) {
if(StringUtils.isNotEmpty(para)) {
para=para+" AND firstClassDeptId:"+ deptIdsArr[0];
}else{
para=para+" firstClassDeptId:"+ deptIdsArr[0];
}
if(StringUtils.isNotEmpty(para)) {
para=para+" AND secondClassDeptId:"+ deptIdsArr[1];
}else{
para=para+" secondClassDeptId:"+ deptIdsArr[1];
}
if(StringUtils.isNotEmpty(para)) {
para=para+" AND thirdClassDeptId:"+ deptIdsArr[2];
}else{
para=para+" thirdClassDeptId:"+ deptIdsArr[2];
}
}
} else {
//刚进来默认查出当前登陆运营人员的卖家服务认证数据 没有在界面选择部门三级联动 没有选择部门查询
if (StringUtils.isEmpty(para)) {
para=para+" operatorErpId:"+ sellerAuthDataQuery.getOperatorErpId();
}
/*
if(StringUtils.isNotEmpty(para)) {
para=para+" AND operatorErpId:"+ sellerAuthDataQuery.getOperatorErpId();
}else{
para=para+" operatorErpId:"+ sellerAuthDataQuery.getOperatorErpId();
}
*/
}
}
return para;
}
<bean id="solrServer92" class="org.apache.solr.client.solrj.impl.HttpSolrServer">
<constructor-arg value="${solr.refresh.data.servers1}" />
<property name="connectionTimeout" value="5000" />
<property name="defaultMaxConnectionsPerHost" value="250" />
<property name="maxTotalConnections" value="2000" />
</bean>
<bean id="solrServer96" class="org.apache.solr.client.solrj.impl.HttpSolrServer">
<constructor-arg value="${solr.refresh.data.servers2}" />
<property name="connectionTimeout" value="5000" />
<property name="defaultMaxConnectionsPerHost" value="250" />
<property name="maxTotalConnections" value="2000" />
</bean>
<bean name="gundogServer" class="com.jd.pop.sellerauth.manager.gundog.impl.SellerAuthSolrGundogServer">
<property name="solrServer" ref="doubleMasterSolrServer"/>
</bean>
<!---配置文件注入-->
<bean name="doubleMasterSolrServer" class="com.jd.pop.sellerauth.manager.gundog.impl.solr.DoubleMasterSolrServer" init-method="init" destroy-method="destroy">
<property name="coreName" value="solrmjfw"/>
<!-- 分2个片 -->
<property name="shardCount" value="${shard.solr.num}"/>
<!-- 两台机器,每台两个tomcat/solr实例,顺序是先遍历端口后遍历ip组成的地址 -->
<property name="master0Servers" value="${solr.update0.servers}"/>
<property name="master0Ports" value="${solr.update0.ports}"/>
<!-- 两台机器,每台两个tomcat/solr实例 -->
<property name="master1Servers" value="${solr.update1.servers}"/>
<property name="master1Ports" value="${solr.update1.ports}"/>
<!-- 查询用的vip -->
<property name="queryServersAndPorts" value="${solr.query.servers}"/>
</bean>
<!-- solr配置 -->
<shard.solr.num>1</shard.solr.num>
<solr.update0.servers>192.168.152.64</solr.update0.servers>
<solr.update0.ports>8080</solr.update0.ports>
<solr.update1.servers>192.168.152.64</solr.update1.servers>
<solr.update1.ports>8089</solr.update1.ports>
<solr.query.servers>192.168.152.64:8080</solr.query.servers>
<!--卖家服务认证服务solr数据刷新分页数量配置-->
<pop-admin-illegal.seller.auth.solr.pagesize>1000</pop-admin-illegal.seller.auth.solr.pagesize>
<solr.refresh.data.servers1>http://192.168.152.64:8080/solr</solr.refresh.data.servers1>
<solr.refresh.data.servers2>http://192.168.152.64:8089/solr</solr.refresh.data.servers2>
================================================================================
ES api:
jars:
<!--es start-->
<dependency>
<artifactId>elasticsearch</artifactId >
<groupId>org.elasticsearch</groupId >
<version>1.1.2</version>
</dependency>
package com.jd.util.es;
import com.google.common.collect.Maps;
import com.jd.common.util.PaginatedList;
import com.jd.common.util.StringUtils;
import com.jd.common.util.base.PaginatedArrayList;
import com.jd.pop.genius.es.EsBuilder;
import com.jd.pop.genius.es.EsClient;
import com.jd.pop.illegal.domain.query.SellerAuthDataQuery;
import com.jd.pop.illegal.domain.sellerauth.gundogpo.SellerAuthDocument;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.query.BoolFilterBuilder;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.sort.SortOrder;
import java.io.IOException;
import java.util.Map;
/**
* Created by niuxiuming on 2015/11/23.
*/
public class SellerAuthEsClient extends EsClient<SellerAuthDocument> {
//可以理解为schema文件
private String indexName;
//es集群的索引类型
private String documentType;
public String getMapping(String indexName, String documentType) {
ImmutableOpenMap<String, MappingMetaData> mappings = getClient().
admin().cluster().prepareState().execute().actionGet().getState().getMetaData().getIndices().get(indexName).getMappings();
String mapping = mappings.get(documentType).source().toString();
System.out.println(mapping);
return mapping;
}
/**
* elastic search
*
* @param sellerAuthDataQuery
* @param pageNo
* @param pageSize
* @return
*/
public PaginatedList<SellerAuthDocument> search(SellerAuthDataQuery sellerAuthDataQuery, int pageNo, int pageSize) {
PaginatedList<SellerAuthDocument> result = new PaginatedArrayList<SellerAuthDocument>();
result.setPageSize(pageSize);
result.setIndex(pageSize);
BoolQueryBuilder queryBuilder = null;
BoolFilterBuilder filterBuilder = null;
EsBuilder builder = new EsBuilder();
builder.initFilterBuilder();
builder.initBoolQueryBuilder();
if (null != sellerAuthDataQuery) {
Boolean isfuzzy = isfuzzyQuery(sellerAuthDataQuery);
if (StringUtils.isNotEmpty(sellerAuthDataQuery.getOperatorErpId())) {
builder.setMust("operatorErpId", sellerAuthDataQuery.getOperatorErpId());
}
if (null != sellerAuthDataQuery.getVenderId()) {
builder.setMust("venderId", sellerAuthDataQuery.getVenderId());
}
if (null != sellerAuthDataQuery.getCheckPass()) {
builder.setMust("checkPass", sellerAuthDataQuery.getCheckPass());
}
if (null != sellerAuthDataQuery.getAuthPass()) {
builder.setMust("authPass", sellerAuthDataQuery.getAuthPass());
}
if (null != sellerAuthDataQuery.getAuthStatus()) {
builder.setMust("authStatus", sellerAuthDataQuery.getAuthStatus());
}
if (StringUtils.isNotEmpty(sellerAuthDataQuery.getDeptIds())) {
String deptIds = sellerAuthDataQuery.getDeptIds();
String[] deptIdsArr = deptIds.split(",");
if (deptIdsArr.length >= 1) {
builder.setMust("firstClassDeptId", deptIdsArr[0]);
}
if (deptIdsArr.length >= 2) {
builder.setMust("secondClassDeptId", deptIdsArr[1]);
}
if (deptIdsArr.length >= 3) {
builder.setMust("thirdClassDeptId", deptIdsArr[2]);
}
}
if (null != sellerAuthDataQuery.getVenderName()) {
builder.setfuzzy("venderName", sellerAuthDataQuery.getVenderName());
}
if (null != sellerAuthDataQuery.getShopName()) {
builder.setfuzzy("shopName", sellerAuthDataQuery.getShopName());
}
if (StringUtils.isNotEmpty(sellerAuthDataQuery.getOpTime())) {
builder.setfuzzy("opTime", sellerAuthDataQuery.getOpTime());
}
}
filterBuilder = builder.buildFilter();
queryBuilder = builder.buildQuery();
//封装查询对象
EsClient client = initSearchRequest(SearchType.QUERY_THEN_FETCH);
client.setPage(pageNo, pageSize);
client.setSort(getSortOrder(sellerAuthDataQuery));
log.info("is filter query : " + isfilterQuery(sellerAuthDataQuery));
log.info("is fuzzy query : " + isfuzzyQuery(sellerAuthDataQuery));
if(isfilterQuery(sellerAuthDataQuery)){
client.setBoolFilterBuilder(filterBuilder);
}
if(isfuzzyQuery(sellerAuthDataQuery)){
client.setBoolQueryBuilder(queryBuilder);
}
client.builder();
transformMapToList(getResponse(), result);
return result;
}
public void transformMapToList(SearchResponse sResponse, PaginatedList<SellerAuthDocument> result) {
if (sResponse != null) {
SearchHits hits = sResponse.getHits();
//总数
long count = hits.getTotalHits();
result.setTotalItem(Integer.parseInt(String.valueOf(count)));
SearchHit[] hitArray = hits.getHits();
for (int i = 0; i < hitArray.length; i++) {
SearchHit hit = hitArray[i];
Map<String, Object> dataMaps = hit.getSource();
log.info(dataMaps.toString());
result.add(buildDoc(dataMaps));
}
}
}
private SellerAuthDocument buildDoc(Map<String, Object> map) {
SellerAuthDocument doc = new SellerAuthDocument();
if (map.get("serviceRank") != null) {
doc.setServiceRank((Double) map.get("serviceRank"));
}
if (map.get("checkPass") != null) {
doc.setCheckPass((Integer) map.get("checkPass"));
}
if (map.get("firstClassDeptId") != null) {
doc.setFirstClassDeptId(Long.valueOf((Integer) map.get("firstClassDeptId")));
}
if (map.get("basePass") != null) {
doc.setBasePass((Integer) map.get("basePass"));
}
if (map.get("thirdClassDeptName") != null) {
doc.setThirdClassDeptName(String.valueOf(map.get("thirdClassDeptName")));
}
if (map.get("venderId") != null) {
doc.setVenderId(Long.valueOf((Integer) map.get("venderId")));
}
if (map.get("operatorErpId") != null) {
doc.setOperatorErpId(String.valueOf(map.get("operatorErpId")));
}
if (map.get("secondClassDeptName") != null) {
doc.setSecondClassDeptName(String.valueOf(map.get("secondClassDeptName")));
}
if (map.get("efficiencyAvg") != null) {
doc.setEfficiencyAvg((Double) map.get("efficiencyAvg"));
}
if (map.get("firstClassDeptName") != null) {
doc.setFirstClassDeptName(String.valueOf(map.get("firstClassDeptName")));
}
if (map.get("thirdClassDeptId") != null) {
doc.setThirdClassDeptId(Long.valueOf((Integer) map.get("thirdClassDeptId")));
}
if (map.get("opTime") != null) {
doc.setOpTime(String.valueOf(map.get("opTime")));
}
if (map.get("reportUrl") != null) {
doc.setReportUrl(String.valueOf(map.get("reportUrl")));
}
if (map.get("efficiencyRank") != null) {
doc.setEfficiencyRank((Double) map.get("efficiencyRank"));
}
if (map.get("efficiencyPass") != null) {
doc.setEfficiencyPass((Integer) map.get("efficiencyPass"));
}
if (map.get("sendTime") != null) {
doc.setSendTime(String.valueOf(map.get("sendTime")));
}
if (map.get("servicePass") != null) {
doc.setServicePass(Integer.valueOf(String.valueOf(map.get("servicePass"))));
}
if (map.get("authPass") != null) {
doc.setAuthPass(new Integer(String.valueOf(map.get("authPass"))));
}
if (map.get("operatorName") != null) {
doc.setOperatorName(String.valueOf(map.get("operatorName")));
}
if (map.get("serviceAvg") != null) {
doc.setServiceAvg(new Double(String.valueOf(map.get("serviceAvg"))));
}
if (map.get("shopName") != null) {
doc.setShopName(String.valueOf(map.get("shopName")));
}
if (map.get("authStatus") != null) {
doc.setAuthStatus(new Integer(String.valueOf(map.get("authStatus"))));
}
if (map.get("secondClassDeptId") != null) {
doc.setSecondClassDeptId(Long.valueOf(String.valueOf(map.get("secondClassDeptId"))));
}
if (map.get("venderName") != null) {
doc.setVenderName(String.valueOf(map.get("venderName")));
}
// indexId=271902015-01,
return doc;
}
private Map<String, SortOrder> getSortOrder(SellerAuthDataQuery sellerAuthDataQuery) {
Map<String, SortOrder> map = Maps.newHashMap();
map.put("opTime", SortOrder.DESC);
return map;
}
/**
* 模糊查询返回true;精准查询返回false
*
* @param sellerAuthDataQuery
* @return
*/
private Boolean isfuzzyQuery(SellerAuthDataQuery sellerAuthDataQuery) {
Boolean isfuzzy = (StringUtils.isNotEmpty(sellerAuthDataQuery.getVenderName()))
|| (StringUtils.isNotEmpty(sellerAuthDataQuery.getShopName()))
|| (StringUtils.isNotEmpty(sellerAuthDataQuery.getOpTime()));
return isfuzzy;
}
/**
* 精准查询返回true
*
* @param sellerAuthDataQuery
* @return
*/
private Boolean isfilterQuery(SellerAuthDataQuery sellerAuthDataQuery) {
Boolean isfilter = (StringUtils.isNotEmpty(sellerAuthDataQuery.getOperatorErpId()))
|| (null != sellerAuthDataQuery.getVenderId())
|| (null != sellerAuthDataQuery.getCheckPass())
|| (null != sellerAuthDataQuery.getAuthPass())
|| (null != sellerAuthDataQuery.getAuthStatus())
|| (StringUtils.isNotEmpty(sellerAuthDataQuery.getDeptIds()));
return isfilter;
}
/**
* 创建索引
* 注意:在生产环节中通知es集群的owner去创建index
*
* @throws java.io.IOException
*/
public void createIndex() throws IOException {
IndicesExistsResponse iRes;
iRes = client.admin().indices().prepareExists(getIndexName()).execute().actionGet();
if (iRes.isExists()) {
client.admin().indices().prepareDelete(getIndexName()).execute().actionGet();
}
client.admin().indices().prepareCreate(getIndexName()).execute().actionGet();
XContentBuilder mapping = org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder()
.startObject()
.startObject(documentType)
.startObject("properties")
.startObject("id")
.field("type", "long")
.field("index", "not_analyzed")
.endObject()
.startObject("venderId")
.field("type", "long")
.field("index", "not_analyzed")
.endObject()
.startObject("checkPass")
.field("type", "integer")
.field("index", "not_analyzed")
.endObject()
.startObject("authPass")
.field("type", "integer")
.field("index", "not_analyzed")
.endObject()
.startObject("servicePass")
.field("type", "integer")
.field("index", "not_analyzed")
.endObject()
.startObject("efficiencyPass")
.field("type", "integer")
.field("index", "not_analyzed")
.endObject()
.startObject("authStatus")
.field("type", "integer")
.field("index", "not_analyzed")
.endObject()
.startObject("serviceRank")
.field("type", "double")
.field("index", "not_analyzed")
.endObject()
.startObject("efficiencyRank")
.field("type", "double")
.field("index", "not_analyzed")
.endObject()
.startObject("serviceAvg")
.field("type", "double")
.field("index", "not_analyzed")
.endObject()
.startObject("efficiencyAvg")
.field("type", "double")
.field("index", "not_analyzed")
.endObject()
.startObject("basePass")
.field("type", "double")
.field("index", "not_analyzed")
.endObject()
.startObject("reportUrl")
.field("store", true)
.field("type", "string")
.field("analyzer", "ik")
.endObject()
.startObject("opTime")
.field("store", true)
.field("type", "string")
.field("index", "not_analyzed")
.endObject()
.startObject("sendTime")
.field("store", true)
.field("type", "string")
.field("index", "not_analyzed")
.endObject()
.startObject("venderName")
.field("store", true)
.field("type", "string")
.field("analyzer", "ik")
.endObject()
.startObject("shopName")
.field("store", true)
.field("type", "string")
.field("analyzer", "ik")
.endObject()
.startObject("operatorErpId")
.field("type", "integer")
.field("index", "not_analyzed")
.endObject()
.startObject("operatorName")
.field("store", true)
.field("type", "long")
.field("index", "not_analyzed")
.endObject()
.startObject("firstClassDeptId")
.field("type", "long")
.field("index", "not_analyzed")
.endObject()
.startObject("firstClassDeptName")
.field("store", true)
.field("type", "string")
.field("analyzer", "ik")
.endObject()
.startObject("secondClassDeptId")
.field("type", "long")
.field("index", "not_analyzed")
.endObject()
.startObject("secondClassDeptName")
.field("store", true)
.field("type", "string")
.field("analyzer", "ik")
.endObject()
.startObject("thirdClassDeptId")
.field("type", "long")
.field("index", "not_analyzed")
.endObject()
.startObject("thirdClassDeptName")
.field("store", true)
.field("type", "string")
.field("analyzer", "ik")
.endObject()
.endObject()
.endObject()
.endObject();
PutMappingResponse putMappingResponse = client.admin().indices()
.preparePutMapping(indexName)
.setType(documentType)
.setSource(mapping)
.execute().actionGet();
}
@Override
protected String getIndexName() {
return indexName;
}
public void setIndexName(String indexName) {
this.indexName = indexName;
}
@Override
protected String getDocumentType() {
return documentType;
}
public void setDocumentType(String documentType) {
this.documentType = documentType;
}
}
spring-config-es.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
default-autowire="byName">
<!---es配置文件 一个集群可以配置多个IP port-->
<bean id="esUtils" class="com.jd.util.es.EsClient" name="esUtils" init-method="init" abstract="true">
<property name="clusterName" value="${pop-admin.es.clusterName}"/>
<property name="nodeIpPortList" value="${pop-admin.es.nodeIpPortList}"/>
<property name="timeoutMillis" value="${pop-admin.es.timeout}"/>
<property name="appName" value="${pop-admin.es.app.name}"/>
</bean>
<!--配置自己的indexName-->
<bean id="sellerAuthEsClient" class="com.jd.util.es.SellerAuthEsClient" parent="esUtils">
<property name="indexName" value="${pop-admin.es.sellerAuth.indexName}"/>
<property name="documentType" value="${pop-admin.es.sellerAuth.documentType}"/>
</bean>
</beans>
<!-- Elastic Search configure -->
<pop-admin.es.clusterName>jsf-elasticsearch-1.7</pop-admin.es.clusterName>
<pop-admin.es.nodeIpPortList>192.168.200.198:9370</pop-admin.es.nodeIpPortList>
<pop-admin.es.timeout>5000</pop-admin.es.timeout>
<pop-admin.es.app.name>legal.man</pop-admin.es.app.name>
<pop-admin.es.sellerAuth.indexName>legalman</pop-admin.es.sellerAuth.indexName>
<pop-admin.es.sellerAuth.documentType>sellerAuth</pop-admin.es.sellerAuth.documentType>
<!-- Elastic Search configure end-->
<!-- Elastic Search configure -->
<pop-admin.es.clusterName>jiesi-37</pop-admin.es.clusterName>
<pop-admin.es.nodeIpPortList>172.20.73.90:9312,172.20.73.91:9312,172.20.73.89:9312,172.20.73.88:9312</pop-admin.es.nodeIpPortList>
<pop-admin.es.timeout>5000</pop-admin.es.timeout>
<pop-admin.es.app.name>legal.man</pop-admin.es.app.name>
<pop-admin.es.sellerAuth.indexName>pop_admin_legal</pop-admin.es.sellerAuth.indexName>
<pop-admin.es.sellerAuth.documentType>seller_auth</pop-admin.es.sellerAuth.documentType>
<!-- Elastic Search configure end-->
private void indexElasticSearchDoc(SellerAuthDocument sellerAuthDocument) {
CallerInfo callerInfo = Profiler.registerInfo(UMPConstant.KEY_ADMIN_LEGAL_METHOD_SellerAuthData_ES_INVOKE, false, true);
try {
sellerAuthEsClient.insert(sellerAuthDocument);
} catch (Exception e) {
Profiler.functionError(callerInfo);
} finally {
Profiler.registerInfoEnd(callerInfo);
}
}
javabeans:
package com.jd.pop.illegal.domain.sellerauth.gundogpo;
import com.jd.pop.genius.es.EsDocument;
import com.jd.pop.illegal.domain.sellerauth.gundog.annotation.*;
/**
* Created with IntelliJ IDEA.
* User: tianshangwen
* Date: 14-11-5
* Time: 下午3:31
* To change this template use File | Settings | File Templates.
*/
@GundogDocument
@Index(name = "collection1")
public class SellerAuthDocument implements EsDocument {
@Id
private String id;
@Field
private Long venderId;
@Field
private Integer checkPass;
@Field
private Integer authPass;
@Field
private Integer servicePass;
@Field
private Integer efficiencyPass;
@Field
private Integer authStatus;
@Field
private Double serviceRank;
@Field
private Double efficiencyRank;
@Field
private Double serviceAvg;
@Field
private Double efficiencyAvg;
@Field
private Integer basePass;
@Field
private String reportUrl;
@Field
private String opTime;
@Field
private String sendTime;
//=============================商家信息数据 包括商家名称、店铺名称、运营人员ERP、运营人员所属三级部门
@Field
private String venderName;
@Field
private String shopName;
@Field
private String operatorErpId;
@Field
private String operatorName;
@Field
private Long firstClassDeptId;
@Field
private String firstClassDeptName;
@Field
private Long secondClassDeptId;
@Field
private String secondClassDeptName;
@Field
private Long thirdClassDeptId;
@Field
private String thirdClassDeptName;
public String getId() {
return venderId + opTime;
}
public void setId(String id) {
this.id = id;
}
public Long getVenderId() {
return venderId;
}
public void setVenderId(Long venderId) {
this.venderId = venderId;
}
public Integer getCheckPass() {
return checkPass;
}
public void setCheckPass(Integer checkPass) {
this.checkPass = checkPass;
}
public Integer getAuthPass() {
return authPass;
}
public void setAuthPass(Integer authPass) {
this.authPass = authPass;
}
public Integer getServicePass() {
return servicePass;
}
public void setServicePass(Integer servicePass) {
this.servicePass = servicePass;
}
public Integer getEfficiencyPass() {
return efficiencyPass;
}
public void setEfficiencyPass(Integer efficiencyPass) {
this.efficiencyPass = efficiencyPass;
}
public Integer getAuthStatus() {
return authStatus;
}
public void setAuthStatus(Integer authStatus) {
this.authStatus = authStatus;
}
public Double getServiceRank() {
return serviceRank;
}
public void setServiceRank(Double serviceRank) {
this.serviceRank = serviceRank;
}
public Double getEfficiencyRank() {
return efficiencyRank;
}
public void setEfficiencyRank(Double efficiencyRank) {
this.efficiencyRank = efficiencyRank;
}
public Double getServiceAvg() {
return serviceAvg;
}
public void setServiceAvg(Double serviceAvg) {
this.serviceAvg = serviceAvg;
}
public Double getEfficiencyAvg() {
return efficiencyAvg;
}
public void setEfficiencyAvg(Double efficiencyAvg) {
this.efficiencyAvg = efficiencyAvg;
}
public Integer getBasePass() {
return basePass;
}
public void setBasePass(Integer basePass) {
this.basePass = basePass;
}
public String getReportUrl() {
return reportUrl;
}
public void setReportUrl(String reportUrl) {
this.reportUrl = reportUrl;
}
public String getOpTime() {
return opTime;
}
public void setOpTime(String opTime) {
this.opTime = opTime;
}
public String getSendTime() {
return sendTime;
}
public void setSendTime(String sendTime) {
this.sendTime = sendTime;
}
public String getVenderName() {
return venderName;
}
public void setVenderName(String venderName) {
this.venderName = venderName;
}
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public String getOperatorErpId() {
return operatorErpId;
}
public void setOperatorErpId(String operatorErpId) {
this.operatorErpId = operatorErpId;
}
public String getOperatorName() {
return operatorName;
}
public void setOperatorName(String operatorName) {
this.operatorName = operatorName;
}
public Long getFirstClassDeptId() {
return firstClassDeptId;
}
public void setFirstClassDeptId(Long firstClassDeptId) {
this.firstClassDeptId = firstClassDeptId;
}
public String getFirstClassDeptName() {
return firstClassDeptName;
}
public void setFirstClassDeptName(String firstClassDeptName) {
this.firstClassDeptName = firstClassDeptName;
}
public Long getSecondClassDeptId() {
return secondClassDeptId;
}
public void setSecondClassDeptId(Long secondClassDeptId) {
this.secondClassDeptId = secondClassDeptId;
}
public String getSecondClassDeptName() {
return secondClassDeptName;
}
public void setSecondClassDeptName(String secondClassDeptName) {
this.secondClassDeptName = secondClassDeptName;
}
public Long getThirdClassDeptId() {
return thirdClassDeptId;
}
public void setThirdClassDeptId(Long thirdClassDeptId) {
this.thirdClassDeptId = thirdClassDeptId;
}
public String getThirdClassDeptName() {
return thirdClassDeptName;
}
public void setThirdClassDeptName(String thirdClassDeptName) {
this.thirdClassDeptName = thirdClassDeptName;
}
public String getIndexId() {
return this.getId();
}
}
=====================================
package com.jd.pop.genius.es;
public interface EsDocument {
java.lang.String getIndexId();
}
相关推荐
在大数据和搜索引擎领域,Elasticsearch (ES) 和 Apache Solr 都是广泛使用的开源技术,它们都基于 Lucene 库,提供高性能、可扩展的全文搜索和分析能力。然而,两者在设计哲学、使用场景、功能特性以及社区支持等...
ES(ElasticSearch)和Solr都是基于Lucene的搜索引擎,它们各自提供了一套搜索框架,用于实现高效的全文搜索功能。由于两者都是在Apache License 2下开源的,因此在选择使用哪种搜索方案时,需要根据不同的使用场景...
Solr、Elasticsearch和Lucene是三个在搜索引擎领域中至关重要的技术,它们共同构建了现代数据检索的基础架构。下面将分别对这三个组件进行详细解释,并探讨它们之间的关系。 **Lucene** Lucene是一个高性能、全文本...
提供了一套solr到elasticsearch的语法翻译引擎,兼容现有的solr语法。同时提供了基于注解的ORM功能, 自动完成实体类对象与elasticsearch结果之间的转换。 你只要进行简单的配置,系统便会会自动完成索引、type/...
Solr 和 ElasticSearch 分析比较 Solr 和 ElasticSearch 是两种流行的搜索引擎,都是基于 Apache Lucene 库的开源搜索引擎。在选择搜索引擎时,需要了解它们的优缺点和比较。 Solr 的优缺点 Solr 是一个成熟、...
(狂神)ElasticSearch快速入门笔记,ElasticSearch基本操作以及爬虫(Java-ES仿京东实战),包含了小狂神讲的东西,特别适合新手学习,笔记保存下来可以多看看。好记性不如烂笔头哦~,ElasticSearch,简称es,es是一个...
**Solr和Elasticsearch 全文检索技术详解** 全文检索是现代搜索引擎技术的重要组成部分,它使得用户可以方便地在海量数据中搜索到所需的信息。本文将深入探讨两种流行的全文检索引擎——Apache Solr和Elasticsearch...
- **Solr** 需要配置 **schema.xml** 文件来定义数据结构,而 **ElasticSearch** 支持 **schemafree** 模型,允许动态添加任意类型的 JSON 对象。 6. **索引管理和配置**: - **Solr** 的索引配置较为复杂,需要...
3. **数据导入导出**: 学会使用Solr的DataImportHandler或者Elasticsearch的Bulk API进行大量数据的导入和导出。 4. **查询优化**: 掌握查询语句的编写,理解查询分析器和过滤器,以及评分机制,提高查询效率和准确...
本课程提供所有代码笔记...14、ElasticSearch下载安装(window以及linux下安装) 15、集群环境搭建 16、客户端Kibana安装与使用 17、集群管理插件head安装使用 18、java api 操作 ES 19、电商项目实战应用等等 ....
Elasticsearch通过简单的RESTful API来隐藏Lucene的复杂性,使得全文检索变得简单。下面是Elasticsearch的详细介绍。 1. Elasticsearch简介 Elasticsearch是一个分布式、RESTful 风格的搜索和数据分析引擎。能够在...
---05Lucene的API介绍-复杂查询.mp4┃---06ElasticSearch简介.mp4┃---07ES和Solr的对比.mp4┃---08CentOS7的安装.mp4┃---09CentOS7的特殊命令.mp4┃---10keepalived说明.mp4┃---11虚拟keepalive
### Elasticsearch与ES-RestAPI技术概述 #### 一、Elasticsearch简介 Elasticsearch是一款高性能的分布式搜索和分析引擎,适用于实时数据处理场景。它基于Lucene构建,提供了强大的分布式多用户全文检索功能,通过...
相较于其他竞品,如Apache Solr(需要Zookeeper进行分布式协调)和Splunk(商业产品),ElasticSearch在实时性、易用性和灵活性上有优势。例如,Solr在建立索引时可能会影响搜索性能,而ElasticSearch则较好地平衡了...
Solr是Apache Lucene项目下的一个企业级搜索服务器,它提供了全文检索、命中高亮、 faceted search(分面搜索)以及与多种数据源的集成等功能。在Java环境中使用Solr,我们需要引入相应的Jar包来支持Java代码与Solr...
5. Solr是一个基于Lucene构建的企业级搜索服务器,它提供了搜索引擎的索引、搜索、排序等功能,并通过RESTful API与各种客户端进行交互。Solr在实现搜索引擎方面,不仅继承了Lucene的强大功能,还提供了分布式搜索、...
Elasticsearch的RESTful API使得集成和使用更加直观,而Solr更多地依赖XML配置。此外,Elasticsearch的实时性能和自动化管理能力也是其优于Solr之处。 总结来说,Elasticsearch因其分布式、实时和易用的特性,成为...
Ik Analyzer是一款开源的、基于Java实现的中文分词器,常用于Solr和Elasticsearch等全文搜索引擎的中文处理。在Solr中使用Ik Analyzer,你需要: 1. 将ik-analyzer解压到Solr的lib目录下。 2. 在schema.xml中定义一...