Spring 初探(7) elasticSearch

1.下载elasticsearch项目
  https://www.elastic.co/downloads/elasticsearch
2.启动命令:elasticsearch
请注意curl由于版本不同,有的需要引号,有的不需要,请根据自己环境,选择
3.客户端tel:
curl 127.0.0.1:9200
{
  "name" : "YPNfYXs",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "ZWiUiHiEQqyvRHAGxKNm4A",
  "version" : {
    "number" : "6.0.1",
    "build_hash" : "601be4a",
    "build_date" : "2017-12-04T09:29:09.525Z",
    "build_snapshot" : false,
    "lucene_version" : "7.0.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}
4.新建 Index,可以直接向 Elastic 服务器发出 PUT 请求
curl -X PUT localhost:9200/test
返回:{"acknowledged":true,"shards_acknowledged":true,"index":"test"}
5.查询所有索引
curl -X GET http://localhost:9200/_cat/indices?v
返回:
health status index uuid                   pri rep docs.count docs.deleted store.size pri.store.size
  yellow open   test  -kXfYM6aR9OTZvm4nsORYQ   5   1          0            0      1.1kb          1.1kb
6.查看所有TYPE
curl localhost:9200/_mapping?pretty=true
7.插入数据
curl -XPUT http://localhost:9200/test/type/1 -d '{
    "user" : "test",
    "message" : "It is ok"
}'
8.代码
Applicationpropertis:
elasticsearch.esNodes=localhost:9200 
elasticsearch.cluster.name=demo-elasticsearch 

pom:
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>
申明:
public interface ElasticSearchRepository extends ElasticsearchRepository<ElastArticle,String> {
}
使用:
    @Autowired
    ElasticsearchRepository<ElastArticle,String> elasticsearchRepository ;

猜你喜欢

转载自leaf-it.iteye.com/blog/2404636
今日推荐