gre作文教程 grep教程( 四 )


  • 使用elasticsearch-head插件
  • 使用elasticsearch提供的Restful接口直接访问
  • 使用elasticsearch提供的API进行访问
4.1使用Restful接口直接访问我们需要使用http请求,介绍两款接口测试工具:postman和Talend API tester 。
  • Talend API tester安装:
这是一款chrome插件,无需下载;
gre作文教程 grep教程

文章插图

  • Postman安装:
Postman官网:https://www.getpostman.com
gre作文教程 grep教程

文章插图

4.2使用Talend API tester进行es客户端操作 。1)Elasticsearch的接口语法curl ‐X \'://:/?\' ‐d \'\'其中:
gre作文教程 grep教程

文章插图

2)创建索引库index并添加映射mapping------PUTPUT 请求体:
article:type类型;相当于这个索引库中有张表叫做article下面定义的这张表中的字段的定义,
字段默认为不索引的;
analyzer:分词器使用标准分词器
{"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"}}}}}
gre作文教程 grep教程

文章插图

在可视化工具elasticsearch-head中查看:
gre作文教程 grep教程

文章插图

3)先创建索引index,再添加mapping ----PUT我们可以在创建索引时设置mapping信息,当然也可以先创建索引然后再设置mapping 。在上一个步骤中不设置maping信息,直接使用put方法创建一个索引,然后设置mapping信息 。请求的url:
PUThttp://127.0.0.1:9200/hello2/article/_mapping请求体:
{"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"}}}}
gre作文教程 grep教程

文章插图

4)删除索引index ----DELETE请求URL:
DELETEhttp://127.0.0.1:9200/hello2
gre作文教程 grep教程

文章插图

5)创建文档document(向索引库中添加内容)---POST请求URL:
POSThttp://127.0.0.1:9200/hello/article/1请求体:
{"id": 1,"title": "ElasticSearch是一个基于Lucene的搜索服务器","content": "它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口 。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索引擎 。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便 。"}
gre作文教程 grep教程

文章插图

在elasticsearch-head中查看:
gre作文教程 grep教程

文章插图

注意,一般我们将_id与id赋相同值 。
6)修改document内容----POST请求URL:
POST http://127.0.0.1:9200/hello/article/1
gre作文教程 grep教程

文章插图

在elasticsearch-head中查看:
gre作文教程 grep教程

文章插图


特别声明:本站内容均来自网友提供或互联网,仅供参考,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。