fix:es 练习

上级 70614a1a
...@@ -37,7 +37,7 @@ public class TestDocument_01_get { ...@@ -37,7 +37,7 @@ public class TestDocument_01_get {
//构建请求 //构建请求
GetRequest getRequest = new GetRequest("test_post", "1"); GetRequest getRequest = new GetRequest("test_post", "1");
//添加可选参数 //添加可选参数
String[] includes = new String[]{"user", "message"}; String[] includes = new String[]{"id", "comment"};
String[] excludes = Strings.EMPTY_ARRAY; String[] excludes = Strings.EMPTY_ARRAY;
FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes); FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes);
getRequest.fetchSourceContext(fetchSourceContext); getRequest.fetchSourceContext(fetchSourceContext);
......
...@@ -36,7 +36,7 @@ public class TestDocument_02_get { ...@@ -36,7 +36,7 @@ public class TestDocument_02_get {
//构建请求 //构建请求
GetRequest getRequest = new GetRequest("test_post", "1"); GetRequest getRequest = new GetRequest("test_post", "1");
//添加可选参数 //添加可选参数
String[] includes = new String[]{"user", "message"}; String[] includes = new String[]{"id", "title"};
String[] excludes = Strings.EMPTY_ARRAY; String[] excludes = Strings.EMPTY_ARRAY;
FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes); FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes);
getRequest.fetchSourceContext(fetchSourceContext); getRequest.fetchSourceContext(fetchSourceContext);
......
...@@ -30,7 +30,7 @@ public class TestDocument_04_add { ...@@ -30,7 +30,7 @@ public class TestDocument_04_add {
public void testAdd() throws IOException { public void testAdd() throws IOException {
//构建请求 //构建请求
IndexRequest request = new IndexRequest("test_post"); IndexRequest request = new IndexRequest("test_post");
request.id("5"); request.id("6");
//构建文档数据 //构建文档数据
Map<String, Object> jsonMap = new HashMap<String, Object>(); Map<String, Object> jsonMap = new HashMap<String, Object>();
jsonMap.put("user", "tomas"); jsonMap.put("user", "tomas");
......
...@@ -30,7 +30,7 @@ public class TestDocument_05_add { ...@@ -30,7 +30,7 @@ public class TestDocument_05_add {
public void testAdd() throws IOException { public void testAdd() throws IOException {
//构建请求 //构建请求
IndexRequest request = new IndexRequest("test_post"); IndexRequest request = new IndexRequest("test_post");
request.id("5"); request.id("7");
//构建文档数据 //构建文档数据
XContentBuilder builder = XContentFactory.jsonBuilder(); XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject(); builder.startObject();
......
...@@ -28,7 +28,7 @@ public class TestDocument_06_add { ...@@ -28,7 +28,7 @@ public class TestDocument_06_add {
public void testAdd() throws IOException { public void testAdd() throws IOException {
//构建请求 //构建请求
IndexRequest request = new IndexRequest("test_post"); IndexRequest request = new IndexRequest("test_post");
request.id("5"); request.id("9");
//构建文档数据 //构建文档数据
request.source("user", "tomas", request.source("user", "tomas",
"message", "trying out es1", "message", "trying out es1",
......
...@@ -39,7 +39,7 @@ public class TestDocument_07_add { ...@@ -39,7 +39,7 @@ public class TestDocument_07_add {
public void testAdd() throws IOException { public void testAdd() throws IOException {
//构建请求 //构建请求
IndexRequest request = new IndexRequest("test_post"); IndexRequest request = new IndexRequest("test_post");
request.id("5"); request.id("10");
//构建文档数据 //构建文档数据
String jsonString = "{\n" + String jsonString = "{\n" +
" \"user\":\"tomas\",\n" + " \"user\":\"tomas\",\n" +
......
...@@ -36,7 +36,7 @@ public class TestDocument_08_update { ...@@ -36,7 +36,7 @@ public class TestDocument_08_update {
@Test @Test
public void testUpdate() throws IOException { public void testUpdate() throws IOException {
//创建请求 //创建请求
UpdateRequest request = new UpdateRequest("test_post", "3"); UpdateRequest request = new UpdateRequest("test_post", "5");
Map<String, Object> jsonMap = new HashMap<>(); Map<String, Object> jsonMap = new HashMap<>();
jsonMap.put("user", "tomas Lee"); jsonMap.put("user", "tomas Lee");
request.doc(jsonMap); request.doc(jsonMap);
......
...@@ -23,6 +23,14 @@ import org.springframework.test.context.junit4.SpringRunner; ...@@ -23,6 +23,14 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.io.IOException; import java.io.IOException;
/**
* 批量操作
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/5/10 14:18
*/
@Slf4j @Slf4j
@SpringBootTest(classes = SearchApplication.class) @SpringBootTest(classes = SearchApplication.class)
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册