其他
没错,你离分布式搜索只差一个Elasticsearch入门!
The following article is from 沉默王二 Author 沉默王二
http://localhost:9200
进行查看(9200 是 Elasticsearch 的默认端口号)。Ctrl+C
组合键——粗暴、壁咚。[Kibana][http] http server running
的信息后,说明服务启动成功了。http://localhost:5601
查看 Kibana 的图形化界面。<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.6.2</version>
</dependency>
public static void main(String[] args) throws IOException {
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(
new HttpHost("localhost", 9200, "http")));
IndexRequest indexRequest = new IndexRequest("writer")
.id("1")
.source("name", "沉默王二",
"age", 18,
"memo", "一枚有趣的程序员");
IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT);
GetRequest getRequest = new GetRequest("writer", "1");
GetResponse getResponse = client.get(getRequest, RequestOptions.DEFAULT);
String sourceAsString = getResponse.getSourceAsString();
System.out.println(sourceAsString);
client.close();
}
}
index()
方法向 Elasticsearch 服务器添加索引。get()
方法向 Elasticsearch 服务器获取索引。getSourceAsString()
用于从响应中获取文档数据源(JSON 字符串的形式)。避坑!使用 Kubernetes 最易犯的 10 个错误