1  使用postman对elasticsearch进行测试

:下载插件: https://www.getpostman.com/apps ,下载时exe文件,双击自动安装,首次打开注册。下面就可以使用进行测试

请求:

响应:

2:elasticsearch中可以使用post,put,get等请求方式,索引原理:https://my.oschina.net/90888/blog/1617292

3:对elasticsearch操作有,post新增索引,数据,put更新索引,数据,get获取,分词等

3.1:新增一条索引,数据,index只能小写。

新增结果:

如果post中没有id值,elasticsearch将会自动创建id,

3.2  查询数据

往查询url POST数据即可:

URL格式:http://xxxhost:8201/qa_xx2/qa_xx3/_search

a. 查询title中包含有my字段的文档。Highlight设置高亮命中的词。POST方法的body:

{
"query": {
"match": {
"title": { //字段
"query": "my "
}
}
},
"highlight": {
"fields": {
"title": { //查询到的文档进行高亮 }
}
}
}

结果:查询成功

{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.2876821,
"hits": [
{
"_index": "indextest",
"_type": "type",
"_id": "i_WWCGIBMRJTfK5J3FTg",
"_score": 0.2876821,
"_source": { //源文档
"title": "this is my fisrt elasticsearch test",
"content": "Elasticsearch is a highly scalable open-source full-text search and analytics engine. It allows you to store, search, and analyze big volumes of data quickly and in near real time. It is generally used as the underlying engine/technology that powers applications that have complex search features and requirements.",
"desc": "结束,字段名相当于列名"
},
"highlight": { //高亮显示
"title": [
"this is <em>my</em> fisrt elasticsearch test"
]
}
}
]
}
}

4  使用javaapi对elasticsearch进行操作

4.1  添加maven依赖  build.gradle

'org.elasticsearch:elasticsearch:6.0.0',
'org.elasticsearch.client:transport:6.0.0',
'com.alibaba:fastjson:1.2.44',

4.2进行测试

    @Test
public void getData() {
try {
Settings settings = Settings.builder().put("cluster.name", "my-esLearn").build();
//创建client
client = new PreBuiltTransportClient(settings)
.addTransportAddress(new TransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
//搜索数据 blog 索引,article,类型,1 id
GetResponse response = client.prepareGet("blog", "article", "1").execute().actionGet();
//输出结果
System.out.println(response.getSource());
//关闭client
client.close();
} catch (Exception e) {
e.printStackTrace();
}
}

结果:

5:使用java api对elasticsearch进行请求并指定ik分词器

   @Test
public void test2() throws IOException { BulkRequestBuilder bulkRequest = client.prepareBulk(); // either use client#prepare, or use Requests# to directly build index/delete requests
bulkRequest.add(client.prepareIndex("twitter", "tweet", "1") //创建索引
.setSource(jsonBuilder() //请求体,数据
.startObject()
.field("analyzer","ik_max_word") //指定分词器
.field("user", "kimchy")
.field("postDate", new Date())
.field("message", "trying out Elasticsearch")
.endObject()
)
); bulkRequest.add(client.prepareIndex("twitter", "tweet", "2")
.setSource(jsonBuilder()
.startObject()
.field("user", "kimchy")
.field("postDate", new Date())
.field("message", "another post")
.endObject()
)
); BulkResponse bulkResponse = bulkRequest.get();
if (bulkResponse.hasFailures()) {
// process failures by iterating through each bulk response item
} BulkItemResponse[] items = bulkResponse.getItems(); //一次发送多个请求,会返回一个响应数组。
DocWriteResponse response = items[0].getResponse();
String index = response.getIndex();
System.out.println(index); //结果 twitter
}

参考:https://www.cnblogs.com/cswuyg/p/5651620.html

javaapi 操作elasticsearch  http://blog.csdn.net/zjcjava/article/details/78659721

英文 文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/docs.html

 Elastic日报 第205期 (2018-03-09)
1. Elasticsearch在电商领域的实战应用
http://t.cn/REEzwES
2.使用Docker和Elasticsearch搭建全文本搜索引擎应用
http://t.cn/REEzUng
3.剖析Elasticsearch索引原理
https://my.oschina.net/90888/blog/1617292

编辑:铭毅天下
归档:https://elasticsearch.cn/article/525
订阅:https://tinyletter.com/elastic-daily 

postman 安装,对elasticsearch进行请求的更多相关文章

  1. (转)postman安装及简单使用

    Postman安装与使用 2018-06-04 22:58 by 虫师, 46636 阅读, 10 评论, 收藏, 编辑 Postman一款非常流行的API调试工具.其实,开发人员用的更多.因为测试人 ...

  2. 浅入深出Vue:工具准备之PostMan安装配置及Mock服务配置

    浅入深出Vue之工具准备(二):PostMan安装配置 由于家中有事,文章没顾得上.在此说声抱歉,这是工具准备的最后一章. 接下来就是开始环境搭建了~尽情期待 工欲善其事必先利其器,让我们先做好准备工 ...

  3. 2.postman安装及使用

    一.postman说明 postman是研发和测试进行接口调试的工具.可以用来很方便的模拟get或者post或者其他方式的请求来调试接口. 二.postman安装 ①作为谷歌浏览器插件安装 参考资料: ...

  4. Postman安装与简单介绍

    Postman简介 Postman是一个 Chrome 扩展,能提供强大的 Web API HTTP 请求调试功能.Postman能够发送任何类型的http请求,支持GET/PUT/POST/DELE ...

  5. 使用postman模拟appium的http请求

    Appium是Server,接收http请求,使用Postman模拟请求 1.anyproxy 1.1.安装和运行 #安装 npm i -g anyproxy # 运行anyproxy,端口默认800 ...

  6. Postman安装及入门实践(以百度搜索为例)

    一.Postman安装 可以FQ的小伙伴可以直接去官网下载:https://www.getpostman.com 如果不能,可以用我的安装包,版本找最新的:链接:https://pan.baidu.c ...

  7. Postman安装教程

    Postman 安装教程 在web开发和一些需要模拟HTTP请求的时候,Postman非常有用. 因为实习的时候接触到了,感觉确实非常好用.就记录下来. 以下是参考其他博主的博文,地址:http:// ...

  8. 如何安装搜索引擎Elasticsearch?

    最近工作中要用到搜索引擎,由于目前用的搜索引擎是LeanCloud 提供的 ,不太好用,不支持范围等搜索,而且每天还收费30元,请求次数也有限制.基于这些原因,我们只好在自己的服务器上部署搜索引擎了. ...

  9. Postman 安装及使用入门教程(我主要使用接口测试)

    1.Postman 安装及使用入门教程(我主要使用接口测试)Postman的English官网:https://www.getpostman.com/chrome插件整理的Postman中文使用教程( ...

随机推荐

  1. JS - 点击事件排除父级标签

    点击事件排除父级标签,这里使用的是stopPropagation()方法.event.stopPropagation(); 对了,这里还用了解除click事件,unbind. 下面这篇博文,介绍挺全的 ...

  2. HTML5实现图片预览功能

    两种方式实现 URL FileReader Index.jsp文件 <%@page contentType="text/html" pageEncoding="UT ...

  3. OpenStack入门之【OpenStack-havana】之单网卡-All In One 安装(基于CentOS6.4)

    这篇文章是自己的一篇老文,分享下,请君慢用.... =========================================== [特别申明]:经过了一段时间的不断学习加不断的测试得出本文, ...

  4. Nginx写IO占用高故障处理

    文章来源:<https://www.centos.bz/2015/04/handle-nginx-write-io-problem/> 故障现象 突然收到一台服务器负载过高告警,紧接着网站 ...

  5. linux下php redis扩展安装

    sudo tar vxzf redis-2.2.7.tgz cd redis-2.2.7 执行sudo /data/service/php54/bin/phpize 在目录下生成配置文件 sudo . ...

  6. Windows Server 2012升级R2过程中意外关闭恢复原系统方法

    2012升级R2过程中强制关闭了计算机,导致再次启动后蓝屏提示"BAD_SYSTEM_CONFIG_INFO".用2012安装盘进入尝试修复失败(安全模式什么的都不用想),进入命令 ...

  7. C程序设计语言习题(3-3)

    编写函数expand(s1,s2), 将字符串s1中类似于a-z一类的速记符号在字符串s2中扩展为等价的完整列表abc……xyz.该函数可以处理大小写字母和数字,并可以处理a-b-c.a-z0-9与a ...

  8. 关于windows 7系统下开启休眠功能的方法

    今天笔者新装了一个windows 7操作系统,装完后,点击开始按钮.鼠标放到关机处的左边扩展选项时,没有发现休眠选项. 于是开始上网查询解决方法,并将过程记录如下: 首先简单的介绍一下休眠功能:休眠( ...

  9. 关于电信宽带wan口地址变成100.64网段的问题解决

    由于之前笔者一直在使用动态域名连接公司vpn.今天在连接vpn的时候总是失败,因动态域名及vpn配置都从未更改过. 于是首先排查动态域名,是否已更新为公司宽带对外的IP.这里笔者先通过nslookup ...

  10. Thinkphp框架下(同服务器下)不同二级域名之间session互通共享设置

    在Thinkphp框架下根目录打开index.php 在头部加入如下代码即可: //入口文件 define('DOMAIN','abc.com');//abc.com换成自己的跟域名 //以下两行是为 ...