Authored by unknown

fix编译bug

@@ -17,6 +17,11 @@ @@ -17,6 +17,11 @@
17 <artifactId>yoho-core-dal</artifactId> 17 <artifactId>yoho-core-dal</artifactId>
18 </dependency> 18 </dependency>
19 <dependency> 19 <dependency>
  20 + <groupId>org.elasticsearch</groupId>
  21 + <artifactId>elasticsearch</artifactId>
  22 + <version>5.4.3</version>
  23 + </dependency>
  24 + <dependency>
20 <groupId>com.yoho.search</groupId> 25 <groupId>com.yoho.search</groupId>
21 <artifactId>search-personalized</artifactId> 26 <artifactId>search-personalized</artifactId>
22 </dependency> 27 </dependency>
@@ -14,10 +14,6 @@ @@ -14,10 +14,6 @@
14 14
15 <dependencies> 15 <dependencies>
16 <dependency> 16 <dependency>
17 - <groupId>com.yoho.search</groupId>  
18 - <artifactId>search-consumer-service</artifactId>  
19 - </dependency>  
20 - <dependency>  
21 <groupId>org.quartz-scheduler</groupId> 17 <groupId>org.quartz-scheduler</groupId>
22 <artifactId>quartz</artifactId> 18 <artifactId>quartz</artifactId>
23 </dependency> 19 </dependency>
@@ -26,17 +22,16 @@ @@ -26,17 +22,16 @@
26 <artifactId>spring-rabbit</artifactId> 22 <artifactId>spring-rabbit</artifactId>
27 </dependency> 23 </dependency>
28 <dependency> 24 <dependency>
29 - <groupId>com.yoho.core</groupId>  
30 - <artifactId>yoho-core-dal</artifactId> 25 + <groupId>com.yoho.search</groupId>
  26 + <artifactId>search-es</artifactId>
31 </dependency> 27 </dependency>
32 <dependency> 28 <dependency>
33 <groupId>com.yoho.search</groupId> 29 <groupId>com.yoho.search</groupId>
34 <artifactId>search-consumer-dal</artifactId> 30 <artifactId>search-consumer-dal</artifactId>
35 </dependency> 31 </dependency>
36 <dependency> 32 <dependency>
37 - <groupId>org.elasticsearch</groupId>  
38 - <artifactId>elasticsearch</artifactId>  
39 - <version>5.4.3</version> 33 + <groupId>com.yoho.search</groupId>
  34 + <artifactId>search-consumer-service</artifactId>
40 </dependency> 35 </dependency>
41 </dependencies> 36 </dependencies>
42 </project> 37 </project>
1 package com.yoho.search.consumer.index.common; 1 package com.yoho.search.consumer.index.common;
2 2
3 -import com.yoho.search.core.es.model.ESBluk;  
4 -import com.yoho.search.core.es.model.SearchParam;  
5 -import com.yoho.search.core.es.model.SearchResult; 3 +import java.util.List;
  4 +import java.util.Set;
  5 +
6 import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse.AnalyzeToken; 6 import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse.AnalyzeToken;
7 import org.elasticsearch.action.bulk.BulkResponse; 7 import org.elasticsearch.action.bulk.BulkResponse;
8 import org.elasticsearch.action.get.GetResponse; 8 import org.elasticsearch.action.get.GetResponse;
9 import org.elasticsearch.action.get.MultiGetResponse; 9 import org.elasticsearch.action.get.MultiGetResponse;
10 import org.elasticsearch.cluster.health.ClusterHealthStatus; 10 import org.elasticsearch.cluster.health.ClusterHealthStatus;
11 11
12 -import java.util.List;  
13 -import java.util.Set; 12 +import com.yoho.search.core.es.model.ESBluk;
  13 +import com.yoho.search.core.es.model.SearchParam;
  14 +import com.yoho.search.core.es.model.SearchResult;
14 15
15 /** 16 /**
16 * 索引管理接口: 管理所有的索引和索引客户端,以及对外提供索引操作接口 17 * 索引管理接口: 管理所有的索引和索引客户端,以及对外提供索引操作接口
@@ -16,7 +16,6 @@ import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse.AnalyzeTok @@ -16,7 +16,6 @@ import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse.AnalyzeTok
16 import org.elasticsearch.action.bulk.BulkResponse; 16 import org.elasticsearch.action.bulk.BulkResponse;
17 import org.elasticsearch.action.get.GetResponse; 17 import org.elasticsearch.action.get.GetResponse;
18 import org.elasticsearch.action.get.MultiGetResponse; 18 import org.elasticsearch.action.get.MultiGetResponse;
19 -import org.elasticsearch.cluster.health.ClusterHealthStatus;  
20 import org.slf4j.Logger; 19 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory; 20 import org.slf4j.LoggerFactory;
22 import org.springframework.beans.factory.annotation.Autowired; 21 import org.springframework.beans.factory.annotation.Autowired;
@@ -43,6 +42,7 @@ import com.yoho.search.core.es.impl.YohoIndexHelper; @@ -43,6 +42,7 @@ import com.yoho.search.core.es.impl.YohoIndexHelper;
43 import com.yoho.search.core.es.model.ESBluk; 42 import com.yoho.search.core.es.model.ESBluk;
44 import com.yoho.search.core.es.model.SearchParam; 43 import com.yoho.search.core.es.model.SearchParam;
45 import com.yoho.search.core.es.model.SearchResult; 44 import com.yoho.search.core.es.model.SearchResult;
  45 +import org.elasticsearch.cluster.health.ClusterHealthStatus;
46 46
47 @Component 47 @Component
48 public class YohoIndexServiceImpl implements IYohoIndexService, ApplicationEventPublisherAware { 48 public class YohoIndexServiceImpl implements IYohoIndexService, ApplicationEventPublisherAware {
@@ -34,6 +34,11 @@ @@ -34,6 +34,11 @@
34 <version>${search.core.version}</version> 34 <version>${search.core.version}</version>
35 </dependency> 35 </dependency>
36 <dependency> 36 <dependency>
  37 + <groupId>com.yoho.search</groupId>
  38 + <artifactId>search-es</artifactId>
  39 + <version>${search.core.version}</version>
  40 + </dependency>
  41 + <dependency>
37 <groupId>org.quartz-scheduler</groupId> 42 <groupId>org.quartz-scheduler</groupId>
38 <artifactId>quartz</artifactId> 43 <artifactId>quartz</artifactId>
39 <version>${quartz.version}</version> 44 <version>${quartz.version}</version>
@@ -19,6 +19,10 @@ @@ -19,6 +19,10 @@
19 </dependency> 19 </dependency>
20 <dependency> 20 <dependency>
21 <groupId>com.yoho.search</groupId> 21 <groupId>com.yoho.search</groupId>
  22 + <artifactId>search-es</artifactId>
  23 + </dependency>
  24 + <dependency>
  25 + <groupId>com.yoho.search</groupId>
22 <artifactId>search-consumer-dal</artifactId> 26 <artifactId>search-consumer-dal</artifactId>
23 </dependency> 27 </dependency>
24 </dependencies> 28 </dependencies>
@@ -42,11 +42,6 @@ @@ -42,11 +42,6 @@
42 <groupId>com.yoho.search</groupId> 42 <groupId>com.yoho.search</groupId>
43 <artifactId>search-consumer-spider</artifactId> 43 <artifactId>search-consumer-spider</artifactId>
44 </dependency> 44 </dependency>
45 - <dependency>  
46 - <groupId>org.elasticsearch</groupId>  
47 - <artifactId>elasticsearch</artifactId>  
48 - <version>2.3.4</version>  
49 - </dependency>  
50 <dependency> 45 <dependency>
51 <groupId>junit</groupId> 46 <groupId>junit</groupId>
52 <artifactId>junit</artifactId> 47 <artifactId>junit</artifactId>
1 -package com.yoho.core.index.service.impl;  
2 -  
3 -import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;  
4 -  
5 -import java.io.IOException;  
6 -import java.net.InetAddress;  
7 -import java.net.UnknownHostException;  
8 -import java.util.HashMap;  
9 -import java.util.Iterator;  
10 -import java.util.Map;  
11 -import java.util.concurrent.ExecutionException;  
12 -  
13 -import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;  
14 -import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;  
15 -import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;  
16 -import org.elasticsearch.action.bulk.BulkItemResponse;  
17 -import org.elasticsearch.action.bulk.BulkRequest;  
18 -import org.elasticsearch.action.bulk.BulkRequestBuilder;  
19 -import org.elasticsearch.action.bulk.BulkResponse;  
20 -import org.elasticsearch.action.get.GetResponse;  
21 -import org.elasticsearch.action.search.SearchRequest;  
22 -import org.elasticsearch.action.search.SearchResponse;  
23 -import org.elasticsearch.action.update.UpdateAction;  
24 -import org.elasticsearch.action.update.UpdateRequest;  
25 -import org.elasticsearch.action.update.UpdateRequestBuilder;  
26 -import org.elasticsearch.action.update.UpdateResponse;  
27 -import org.elasticsearch.client.Requests;  
28 -import org.elasticsearch.client.transport.TransportClient;  
29 -import org.elasticsearch.common.settings.Settings;  
30 -import org.elasticsearch.common.transport.InetSocketTransportAddress;  
31 -import org.elasticsearch.index.query.QueryBuilder;  
32 -import org.elasticsearch.index.query.QueryBuilders;  
33 -import org.elasticsearch.search.builder.SearchSourceBuilder;  
34 -import org.junit.Before;  
35 -import org.junit.Test;  
36 -  
37 -/**  
38 - * Created by apple on 16/8/6.  
39 - */  
40 -public class EsTest {  
41 - private TransportClient client;  
42 -  
43 - @Before  
44 - public void createEsClient() throws UnknownHostException {  
45 - Settings settings = Settings.settingsBuilder()  
46 - // .put("cluster.name", "yohosearch111")  
47 - .put("cluster.name", "yohosearch_zhurui").put("client.transport.sniff", true).build();  
48 - client = TransportClient.builder().settings(settings).build().addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));  
49 - }  
50 -  
51 - @Test  
52 - public void deleteMyStroe() {  
53 - DeleteIndexResponse deleteIndexResponse = client.admin().indices().prepareDelete("yoho_productindex_1470727824964_20160809153024964").get();  
54 - System.out.println(deleteIndexResponse.getHeaders());  
55 -  
56 - }  
57 -  
58 - @Test  
59 - public void queryAllIndex() {  
60 - ClusterStateResponse response = client.admin().cluster().prepareState().execute().actionGet();  
61 - String[] indexs = response.getState().getMetaData().getConcreteAllIndices();  
62 - for (String index : indexs) {  
63 - System.out.println(index);//  
64 - }  
65 - }  
66 -  
67 - @Test  
68 - public void createMappingTest() {  
69 - CreateIndexResponse rssp = client  
70 - .admin()  
71 - .indices()  
72 - .prepareCreate("my_store")  
73 - .addMapping(  
74 - "products",  
75 - "{\n" + " \"products\": {\n" + " \"properties\": {\n" + " \"productID\": {\n" + " \"type\": \"string\",\n"  
76 - + " \"index\": \"not_analyzed\"\n" + " }\n" + " }\n" + " }\n" + " }").get();  
77 - System.out.println(rssp.getHeaders());  
78 - }  
79 -  
80 - @Test  
81 - public void bulktest() throws IOException {  
82 - BulkRequestBuilder bulkRequest = client.prepareBulk();  
83 - bulkRequest.add(client.prepareIndex("my_store1", "products", "1").setSource(  
84 - jsonBuilder().startObject().field("price", 10).field("productID", "XHDK-A-1293-#fJ3").endObject()));  
85 - bulkRequest.add(client.prepareIndex("my_store2", "products", "2").setSource(  
86 - jsonBuilder().startObject().field("price", 20).field("productID", "KDKE-B-9947-#kL5").endObject()));  
87 - bulkRequest.add(client.prepareIndex("my_store3", "products1", "3").setSource(  
88 - jsonBuilder().startObject().field("price", 30).field("productID", "JODL-X-1937-#pV7").endObject()));  
89 - bulkRequest.add(client.prepareIndex("my_store", "products", "4").setSource(  
90 - jsonBuilder().startObject().field("price", 40).field("productID", "QQPX-R-3956-#aD8").endObject()));  
91 - BulkResponse bulkResponse = bulkRequest.get();  
92 - if (bulkResponse.hasFailures()) {  
93 - System.out.println("failure");  
94 - }  
95 - }  
96 -  
97 - @Test  
98 - public void queryFilterTerm() {  
99 - QueryBuilder queryBuilder = QueryBuilders.termQuery("productID", "XHDK-A-1293-#fJ3");  
100 - SearchResponse s = client.prepareSearch("my_store").setTypes("products").setQuery(queryBuilder).get();  
101 - System.out.println(s.toString());  
102 - }  
103 -  
104 - @Test  
105 - public void basequerytest() {  
106 - QueryBuilder queryBuilder = QueryBuilders.matchQuery("productID", "XHDK-A-1293-#fJ3");  
107 - SearchResponse s = client.prepareSearch("my_store").setTypes("products").setQuery(queryBuilder).get();  
108 - System.out.println(s.toString());  
109 - }  
110 -  
111 - @Test  
112 - public void basequeryAndFiltertest() {  
113 - QueryBuilder filterBuilder = QueryBuilders.termQuery("price", 10);  
114 - SearchResponse s = client.prepareSearch("my_store").setTypes("products").setQuery(filterBuilder).get();  
115 - System.out.println(s.toString());  
116 - }  
117 -  
118 - @Test  
119 - public void filterQueryTest() {  
120 - QueryBuilder queryBuilder = QueryBuilders.matchQuery("productID", "XHDK-A-1293-#fJ3");  
121 - QueryBuilder filterBuilder = QueryBuilders.termQuery("price", 10);  
122 - QueryBuilder query = QueryBuilders.boolQuery().must(queryBuilder).filter(filterBuilder);  
123 - // searchSourceBuilder.postFilter(filterBuilder); 后置过滤器  
124 - SearchResponse s = client.prepareSearch("my_store").setTypes("products").setQuery(query).get();  
125 - System.out.println(s.toString());  
126 - }  
127 -  
128 - @Test  
129 - public void SearchSourceBuilderTEst() throws ExecutionException, InterruptedException {  
130 - SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();  
131 - QueryBuilder queryBuilder = QueryBuilders.matchQuery("productID", "XHDK-A-1293-#fJ3");  
132 - QueryBuilder filterBuilder = QueryBuilders.termQuery("price", 10);  
133 - QueryBuilder query = QueryBuilders.boolQuery().must(queryBuilder).filter(filterBuilder);  
134 - searchSourceBuilder.query(query);  
135 - // searchSourceBuilder.postFilter(filterBuilder); 后置过滤器  
136 - SearchRequest request = Requests.searchRequest("my_store").types("products");  
137 - request.source(searchSourceBuilder.toString());  
138 - System.out.println(searchSourceBuilder.toString());  
139 - // System.out.println(client.search(request).get().toString());  
140 - }  
141 -  
142 - @Test  
143 - public void boolQueryTest() throws ExecutionException, InterruptedException {  
144 - SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();  
145 - QueryBuilder t1 = QueryBuilders.termQuery("productID", "XHDK-A-1293-#fJ3");  
146 - QueryBuilder t2 = QueryBuilders.termQuery("price", 10);  
147 - QueryBuilder t4 = QueryBuilders.termQuery("price", 30);  
148 - searchSourceBuilder.query(QueryBuilders.boolQuery().should(t1).should(t2).mustNot(t4));  
149 - System.out.println(searchSourceBuilder);  
150 - SearchRequest request = Requests.searchRequest("my_store").types("products");  
151 - request.source(searchSourceBuilder.toString());  
152 - System.out.println(client.search(request).get().toString());  
153 - }  
154 -  
155 - @Test  
156 - public void updateDocTest() throws IOException, ExecutionException, InterruptedException {  
157 - GetResponse rs = client.prepareGet("my_store", "products", "1").get();  
158 - System.out.println("before:" + rs.getSourceAsString());  
159 - UpdateRequest updateRequest = new UpdateRequest("my_store", "products", "1").doc(jsonBuilder().startObject().field("price", 12).endObject());  
160 - client.update(updateRequest).get();  
161 - System.out.println("after" + client.prepareGet("my_store", "products", "1").get().getSourceAsString());  
162 -  
163 - }  
164 -  
165 - @Test  
166 - public void UpdateRequestBuilderTest() throws IOException {  
167 - GetResponse rs = client.prepareGet("my_store", "products", "1").get();  
168 - System.out.println("before:" + rs.getSourceAsString());  
169 - UpdateRequestBuilder request = new UpdateRequestBuilder(client, UpdateAction.INSTANCE, "my_store", "products", "1");  
170 - UpdateResponse re = request.setDoc(jsonBuilder().startObject().field("price", 12).endObject()).get();  
171 - System.out.println(re.toString());  
172 - System.out.println("after" + client.prepareGet("my_store", "products", "1").get().getSourceAsString());  
173 - }  
174 -  
175 - @Test  
176 - public void bulkUpdateTest() throws ExecutionException, InterruptedException {  
177 - final BulkRequest request = Requests.bulkRequest();  
178 - for (int i = 0; i < 10; i++) {  
179 - Map<String, Object> map = new HashMap<String, Object>();  
180 - map.put("id", i);  
181 - map.put("productId", i);  
182 - request.add(Requests.indexRequest("productindex").type("productindex").id(i + "").source(map));  
183 - if (i % 2 == 0) {  
184 - request.add(Requests.deleteRequest("productindex").type("productindex").id(i + ""));  
185 - }  
186 - }  
187 - client.bulk(request).get();  
188 - }  
189 -  
190 - @Test  
191 - public void bulkdeleteTest() throws ExecutionException, InterruptedException {  
192 - final BulkRequest request = Requests.bulkRequest();  
193 - for (int i = 0; i < 10; i++) {  
194 - request.add(Requests.deleteRequest("my_index").type("zhurui").id(i + ""));  
195 - }  
196 - client.bulk(request).get();  
197 - }  
198 -  
199 - @Test  
200 - public void bulkaddTest() throws ExecutionException, InterruptedException {  
201 - final BulkRequest request = Requests.bulkRequest();  
202 - for (int i = 0; i < 10; i++) {  
203 - Map<String, Object> map = new HashMap<String, Object>();  
204 - map.put("id", i);  
205 - map.put("productId", i);  
206 - map.put("productName", "zhurui");  
207 - map.put("nickname", "markeloff" + i);  
208 - request.add(Requests.indexRequest("my_index").type("test").id(i + "").source(map));  
209 - }  
210 - Iterator<BulkItemResponse> iterator = client.bulk(request).get().iterator();  
211 - while (iterator.hasNext()) {  
212 - BulkItemResponse bulkItemResponse = iterator.next();  
213 - System.out.println(bulkItemResponse.getFailureMessage());  
214 - }  
215 - }  
216 -  
217 -}