public String insertData23(@RequestBody List<Map<String, Object>> dataList) throws IOException { BulkRequest bulkRequest = new BulkRequest(); for (Map<String, Object> data : dataList) { IndexRequest indexRequest = new IndexRequest("tp_portflux_ip网管_2023_05_12"); indexRequest.source(data); bulkRequest.add(indexRequest); } BulkResponse bulkResponse = client.bulk(bulkRequest, RequestOptions.DEFAULT); if (bulkResponse.hasFailures()) { // 处理失败情况 return "fail"; } else { return "success"; } } 查询这个索引中的数据
时间: 2024-01-20 21:04:46 浏览: 120
List<Map<String, List<String>>> data保存到SharedPreference和读取
4星 · 用户满意度95%
您可以使用Elasticsearch的Java客户端从索引中检索数据。以下是一个简单的示例,演示如何从"tp_portflux_ip网管_2023_05_12"索引中检索所有文档:
```
SearchRequest searchRequest = new SearchRequest("tp_portflux_ip网管_2023_05_12");
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
SearchHits hits = searchResponse.getHits();
for (SearchHit hit : hits) {
String sourceAsString = hit.getSourceAsString();
// 对sourceAsString进行解析,获取文档中的各个字段的值
// ...
}
```
这段代码将返回名为"tp_portflux_ip网管_2023_05_12"的索引中的所有文档,您可以使用获取的SearchHit对象检索文档的各个字段的值。
阅读全文