Elasticsearch在windows上安装与使用

Elasticsearch简称ES。

是一个全文搜索服务器,也可作为NoSQL数据库,存储任意格式的文档和数据,也可做大数据的分析,是一个跨界开源产品。

ES的特点:

  全文搜索引擎

  文档存储和查询

  大数据分析

  提供了REST API,用来简化对ES的操作

  常常配合传统数据库一起使用,ES用来负责大数据的查询、搜索、统计分析

1.下载

elasticsearch-6.8.3.zip  https://www.elastic.co/downloads/past-releases#elasticsearch

2.启动

解压 elasticsearch-6.8.3.zip

打开cmd,进入elasticsearch的bin

elasticsearch

9200端口是对外的RESTFul接口,9300端口是ES内部使用的端口

启动后在浏览器 http://localhost:9200/

说明:

  name代表这台ES的名字

  cluster_name默认名字是elasticsearch。ES的集群方式是通过广播在同一个网络中寻找cluster_name一样的ES

  如果想修改配置,可以在config/elasticsearch.yml配置

3.基本概念

  Index:是Document的集合,Index包含了Type,相当于数据库

  Type:用来进一步组织Document,一个Index可以有多个Type,相当于表

  Document:文档,是ES能够存储和搜索的基本信息,Document属于Type,相当于行数据,json格式的

  Node:节点,是集群里的一台ES Server,用于Document的存储和查询

  Shards:分区,Index超过了单个节点存储的限制,就会将Index进行分区

  Replicas:复制分区,将Index分为多个分区,Index的分区为主分区,复制的分区为复制分区

4.基本使用

  (1)添加文档

curl -XPOST 'localhost:9200/store/category/1?pretty' -H 'Content-type:application/json' -d'{"name":"soap","type":"cleaning","postDate":"2019-9-15","message":"this is a first data"}'

  (2)根据主键查询

curl -XGET 'localhost:9200/store/category/1?pretty'

   (3)根据主键更新

 curl -XPUT 'localhost:9200/store/category/1?pretty' -H 'Content-type:application/json' -d'{"name":"soap123","type":"cleaning","postDate":"2019-9-15T23:10:10","message":"update data"}'

   只更新message

curl -XPOST 'localhost:9200/store/category/1?pretty' -H 'Content-type:applicat                                                                                                                ion/json' -d'{"doc":{"message":"only update message"}}'

   (4)根据主键删除

curl -XDELETE 'localhost:9200/store/category/1?pretty'

   (5)搜索

curl -XPOST 'localhost:9200/store/category/_search?pretty'

     全文搜索

 curl -XPOST 'localhost:9200/store/category/_search?pretty' -H 'Content-type:application/json' -d'{"query":{"match":{"message":"data"}}}'

    精确搜索

curl -XPOST 'localhost:9200/store/category/_search?pretty' -H 'Content-type:application/json' -d'{"query":{"term":{"type":"cleaning"}}}'

     查询总数

  将_count替换_search

curl -XPOST 'localhost:9200/store/category/_count?pretty' -H 'Content-type:application/json' -d'{"query":{"match":{"message":"data"}}}'

     联合查询

curl -XPOST 'localhost:9200/store/category/_search?pretty' -H 'Content-type:application/json' -d'{"query":{"bool":{"must":[{"term":{"type":"eating"}},{"match":{"message":"second"}}]}}}'

     翻页,使用from和size

 curl -XPOST 'localhost:9200/store/category/_search?pretty' -H 'Content-type:application/json' -d'{"from":1,"size":1,"query":{"match":{"message":"data"}}}'

 说明:

  安装了git就会带有curl功能了

 数据可视化

posted @ 2019-09-09 18:28  慕尘  阅读(1710)  评论(0编辑  收藏  举报