init project
This commit is contained in:
51
acs/hd/nladmin-system/src/test/java/es/Test.java
Normal file
51
acs/hd/nladmin-system/src/test/java/es/Test.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package es;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.elasticsearch.action.bulk.BulkRequest;
|
||||
import org.elasticsearch.action.bulk.BulkResponse;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.springframework.boot.autoconfigure.web.ResourceProperties;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) throws IOException {
|
||||
// 解析查询出来的数据
|
||||
// List<ResourceProperties.Content> contents = new HtmlParseUtil().parseJD(keywords);
|
||||
List<ResourceProperties.Content> contents = null;
|
||||
// 封装数据到索引库中!
|
||||
BulkRequest bulkRequest = new BulkRequest();
|
||||
bulkRequest.timeout(TimeValue.timeValueMinutes(2));
|
||||
bulkRequest.timeout("2m");
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", IdUtil.simpleUUID());
|
||||
json.put("name", "123");
|
||||
|
||||
/* for (int i = 0; i < contents.size(); i++) {
|
||||
bulkRequest
|
||||
.add(new IndexRequest("jd_goods")
|
||||
|
||||
.source(json, XContentType.JSON));
|
||||
}*/
|
||||
bulkRequest
|
||||
.add(new IndexRequest("jd_goods")
|
||||
|
||||
.source(json, XContentType.JSON));
|
||||
RestHighLevelClient restHighLevelClient = new RestHighLevelClient(
|
||||
RestClient.builder(
|
||||
new HttpHost("47.97.157.227", 9200, "http")));
|
||||
BulkResponse bulkResponse =
|
||||
restHighLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT);
|
||||
|
||||
boolean b = bulkResponse.hasFailures();
|
||||
System.out.println(b);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user