es(三)使用postman来管理es数据


推荐链接

1.安装Postman工具

Postman中文版是postman这款强大网页调试工具的windows客户端,提供功能强大的Web API & HTTP 请求调
试。软件功能非常强大,界面简洁明晰、操作方便快捷,设计得很人性化。Postman中文版能够发送任何类型的
HTTP 请求 (GET, HEAD, POST, PUT..),且可以附带任何数量的参数。

2.下载Postman工具

Postman官网:(https://www.getpostman.com)

3.使用Postman工具进行Restful接口访问

--3.1ElasticSearch的接口语法

curl ‐X<VERB> '<PROTOCOL>://<HOST>:<PORT>/<PATH>?<QUERY_STRING>' ‐d '<BODY>'

3.2创建索引index和映射mapping

  • 请求url:PUT localhost:9200/blog1
  • 请求体:
{
    "mappings": {
        "article": {
            "properties": {
                "id": {
                	"type": "long",
                    "store": true,
                    "index":"not_analyzed"
                },
                "title": {
                	"type": "text",
                    "store": true,
                    "index":"analyzed",
                    "analyzer":"standard"
                },
                "content": {
                	"type": "text",
                    "store": true,
                    "index":"analyzed",
                    "analyzer":"standard"
                }
            }
        }
    }
}
  • postman截图

--3.3 创建索引后设置Mapping

我们可以在创建索引时设置mapping信息,当然也可以先创建索引然后再设置mapping。
在上一个步骤中不设置maping信息,直接使用put方法创建一个索引,然后设置mapping信息。

  • 请求的url:
{
    "hello": {
            "properties": {
                "id":{
                	"type":"long",
                	"store":true
                },
                "title":{
                	"type":"text",
                	"store":true,
                	"index":true,
                	"analyzer":"standard"
                },
                "content":{
                	"type":"text",
                	"store":true,
                	"index":true,
                	"analyzer":"standard"
                }
            }
        }
  }
  • PostMan截图
  • 删除索引index
  • 请求url:DELETE localhost:9200/blog1
  • postman截图:

--3.5创建文档document

  • 请求url:POST localhost:9200/blog1/article/1
    请求体:
{
	"id":1,
	"title":"ElasticSearch是一个基于Lucene的搜索服务器",
	"content":"它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。"
}

3.6 修改文档document

请求url:POST localhost:9200/blog1/article/1
请求体:

{
"id":1,
"title":"【修改】ElasticSearch是一个基于Lucene的搜索服务器",
"content":"【修改】它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch
是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索引擎。设计用于云计算中,能够
达到实时搜索,稳定,可靠,快速,安装使用方便。"
}

postman截图:

--3.7删除文档document

  • 请求url:DELETE localhost:9200/blog1/article/1
  • postman截图:

--3.8查询文档-根据id查询

  • 请求url:GET localhost:9200/blog1/article/1
  • postman截图:

--3.9查询文档-querystring(分词分析)查询

先把查询内容进行分词,分完后再进行查询

  • 请求url:
  • 请求体:
{
    "query": {
        "query_string": {
            "default_field": "title",//指定默认搜索域
            "query": "搜索服务器"
        }
    }
}
  • postman截图:

注意:
将搜索内容"搜索服务器"修改为"钢索",同样也能搜索到文档,该原因会在下面讲解中得到答案

{
    "query": {
        "query_string": {
            "default_field": "title",
            "query": "钢索"
        }
    }
}

--3.10查询文档-term查询

关键词查询,对于汉字只能单个字进行查询

  • 请求url:POST localhost:9200/blog1/article/_search
  • 请求体:
{
    "query": {
        "term": {
            "title": "搜索"
        }
    }
}
  • postman截图:
原文地址:https://www.cnblogs.com/psyduck/p/14462990.html