ElasticSearch部署与启动

下载ElasticSearch 5.6.8版本
https://www.elastic.co/downloads/past-releases/elasticsearch-5-6-8

资源\配套软件中也提供了安装包
无需安装,解压安装包后即可使用
在cmd命令提示符下,进入ElasticSearch安装目录下的bin目录,执行命令
 
elasticsearch
即可启动。
我们打开浏览器,在地址栏输入http://127.0.0.1:9200/ 即可看到输出结果
{
"name" : "uV2glMR",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "RdV7UTQZT1‐Jnka9dDPsFg",
"version" : {
"number" : "5.6.8",
"build_hash" : "688ecce",
"build_date" : "2018‐02‐16T16:46:30.010Z",
"build_snapshot" : false,
"lucene_version" : "6.6.1"
},
"tagline" : "You Know, for Search"
}

PostMan中操作调用RestAPI

1.新建索引

以put方式提交,如:

http://localhost:9200/tensquare_elasticsearch

成功后返回:

{
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "tensquare_elasticsearch"
}  

2.新建文档

http://localhost:9200/tensquare_elasticsearch/article

成功后返回:

{
    "_index": "tensquare_elasticsearch",
    "_type": "article",
    "_id": "AXF8wNJoeRSZVheYL50J",
    "_version": 1,
    "result": "created",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "created": true
}

3.查询全部文档

http://localhost:9200/tensquare_elasticsearch/article/_search

返回:

{
    "took": 83,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 1,
        "hits": [
            {
                "_index": "tensquare_elasticsearch",
                "_type": "article",
                "_id": "AXF8wNJoeRSZVheYL50J",
                "_score": 1,
                "_source": {
                    "title": "spring教程",
                    "content": "spring框架教程"
                }
            }
        ]
    }
}

4.修改文档

http://localhost:9200/tensquare_elasticsearch/article/AXF8wNJoeRSZVheYL50J

红色部分为:id值(注意:当id值不存在的时候默认为添加操作,id值存在为修改操作。)

修改成功后返回:

{
    "_index": "tensquare_elasticsearch",
    "_type": "article",
    "_id": "AXF8wNJoeRSZVheYL50J",
    "_version": 2,
    "result": "updated",
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "created": false
}

5.按照id查询

http://localhost:9200/tensquare_elasticsearch/article/1

6.基本匹配查询

http://localhost:9200/tensquare_elasticsearch/article/_search?q=title:spring教程

7.模糊查询

http://localhost:9200/tensquare_elasticsearch/article/_search?q=title:*s*