elastic 的官网 /downloads/elasticsearch 获取最新版本的Elasticsearch。解压文档后,按照下面的操作
cd elasticsearch-<version>
./bin/elasticsearch.bat
此时,Elasticsearch运行在本地的9200端口,在浏览器中输入网址“localhost:9200/”,
使用postman , PUT类型, 127.0.0.1:9200/google/emp/1
将HTTP命令由PUT 改为GET可以用来检索文档,同样的,可以使用DELETE命令来删除文档,以及使用HEAD 指令来检查文档是否存在。如果想更新已存在的文档,只需再次PUT。
Smith
的雇员。这个方法一般涉及到一个查询字符串(_query-string)搜索,因为我们通过一个URL参数来传递查SpringBoot默认支持两种技术来和ES交互:
需要导入jest的工具包(io.searchbox.client.JestClient)
<dependency><groupId>io.searchbox</groupId><artifactId>jest</artifactId><version>6.3.1</version>
</dependency>
spring.elasticsearch.jestt.uris=192.168.99.100:9200
@Data
public class Article {@JestIdprivate Integer id;private String author;private String title;private String content;
@AutowiredJestClient jestClient;//添加@Testvoid contextLoads() {Article article = new Article(1, "allen", "王武", "helloworld");println(article);//修改也可以用saveIndex index = new Index.Builder(article).index("megacorp").type("news").build(); ute(index);}//获取@Testpublic void search(){//获取aaa索引中id为1的Article对象String json = "";Search search = new Search.Builder(json).addIndex("megacorp").addType("news").build(); SearchResult result = ute(search );}
注意:SpringData和ES版本需要适配
.versions
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-elasticsearch</artifactId></dependency>
st.uris=192.168.99.100:9200
spring.data.elasticsearch.cluster-name=elasticsearch
spring.data.elasticsearch.cluster-nodes=192.168.99.100:9300
@Data
@Document(indexName="megacorp", type="news")
public class Book{@JestIdprivate Integer id;private String author;private String title;
public interface BookRepository extends ElasticseanchRepository<Book,Integer> {
}
@AutowiredBookRepository bookRepository ;//添加@Testvoid contextLoads() {Book book = new Book();bookRepository.index(book);}
@AutowiredElasticsearchRestTemplate elasticsearchRestTemplate;//添加@Testvoid contextLoads() {Article article = new Article(1, "allen", "bbb", "helloworld");println(article);//修改也可以用saveelasticsearchRestTemplate.save(article);}//获取@Testpublic void test02(){//获取aaa索引中id为1的Article对象Article article = ("1", Article.class);System.out.println(article);}
本文发布于:2024-01-27 22:15:22,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17063649232953.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |