elasticsearch的percolator操作
es的普通查询是通过某些条件来查询满足的文档,percolator则不同,先是注册一些条件,然后查询一条文档是否满足其中的某些条件。
es的percolator特性在数据分类、数据路由、事件监控和预警方面都有很好的应用。
第一步是建立名为percolate的索引,包含一个字段message
curl -XPUT 'localhost:9200/percolate' -d'{
"mappings":{
"my_type":{
"properties":{
"message":{
"type":"string"
}
}
}
}
}'
第二步,注册一个percolator查询
第三步,构建查询
第四步,查看是否有匹配的条件
第二步到第四步的代码如下,代码基于es 2.1版本:
QueryBuilder qb = QueryBuilders.termQuery("message", "bonsai");
try {
//Index the query = register it in the percolator
//把查询条件添加到索引中,myDesignatedQueryName为定义的查询名
client.prepareIndex("percolate", ".percolator", "myDesignatedQueryName")
.setSource( XContentFactory.jsonBuilder()
.startObject()
// Register the query,添加查询记录
.field("query", qb)
.endObject())
.setRefresh(true) // Needed when the query shall be available immediately
.execute().actionGet();
//上面的term查询定义名为:myDesignatedQueryName XContentBuilder docBuilder = XContentFactory.jsonBuilder().startObject();
//This is needed to designate the document
docBuilder.field("doc").startObject();
docBuilder.field("message", "A new bonsai tree in the office");
docBuilder.endObject();
docBuilder.endObject(); //Percolate查询
PercolateResponse response = client.preparePercolate()
.setIndices("percolate")
.setDocumentType("message")
.setSource(docBuilder).execute().actionGet(); //获取查询query后处理逻辑
for(PercolateResponse.Match match : response) {
//创建percolate时指定的ID,根据查询ID在做相应的操作
System.out.println("percolate ID: "+match.getId());
System.out.println("percolate Index Name: " +match.getIndex());
}
} catch (ElasticsearchException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
输出结果为:
percolate ID: myDesignatedQueryName
percolate Index Name: percolate
elasticsearch的percolator操作的更多相关文章
- ElasticSearch+Kibana 索引操作
ElasticSearch+Kibana 索引操作 一 前言 ElasticiSearch 简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引 ...
- elasticsearch的索引操作和文档操作总结
参考文档:https://es.xiaoleilu.com/010_Intro/00_README.html 一.索引操作 1.查看当前节点的所有的index 查看当前节点的所有的index [roo ...
- ElasticSearch之CURL操作(有空再去整理)
https://www.cnblogs.com/jing1617/p/8060421.html ElasticSearch之CURL操作 CURL的操作 curl是利用URL语法在命令行方式下工 ...
- Es图形化软件使用之ElasticSearch-head、Kibana,Elasticsearch之-倒排索引操作、映射管理、文档增删改查
今日内容概要 ElasticSearch之-ElasticSearch-head ElasticSearch之-安装Kibana Elasticsearch之-倒排索引 Elasticsearch之- ...
- ElasticSearch+Kibana 索引操作( 附源码)
一 前言 ElasticiSearch 简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elastics ...
- elasticsearch(3) 数据操作-更新
一 更新整个文档 更新整个文档的方法和存放数据的方式是相同的,通过PUT 127.0.0.1/test/test/1 我们可以把test/test/1下的文档更新为新的文档 例: PUT 127.0 ...
- ElasticSearch文档操作介绍三
ElasticSearch文档的操作 文档存储位置的计算公式: shard = hash(routing) % number_of_primary_shards 上面公式中,routing 是一个可变 ...
- 初识Elasticsearch,bulk 操作的遇到的那些事
bulk api可以在单个请求中一次执行多个文档的 create . index . update 或 delete 操作 批量操作的行为(action)必须是以下几种: 行为 解释 create 当 ...
- Elasticsearch 相关 api 操作
A. es 操作 1. 检查 es 集群健康状态 2. 获取集群中的节点列表 3. 创建索引 4. 获取索引 5. 索引文档 6. 查询文档 7. 删除索引 8. 更新文档 9. 删除文档 10. 批 ...
随机推荐
- HDU 1495 非常可乐(数论,BFS)
非常可乐 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- [51nod1357]密码锁
有一个密码锁,其有N位,每一位可以是一个0~9的数字,开启密码锁需要将锁上每一位数字转到解锁密码一致.这个类似你旅行用的行李箱上的密码锁,密码锁的每一位其实是一个圆形转盘,上面依次标了0,1,...9 ...
- A. Vasya and Football
A. Vasya and Football time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- android银行卡匹配、详情展开动画、仿爱奇艺视频拖拽、扫码识别手机号等源码
Android精选源码 android实现银行卡匹配信息源码 android实现可以展开查看详情的卡片 下拉刷新,上拉加载,侧滑显示菜单等效果RefreshSwipeRecyclerview andr ...
- android小说阅读源码、bilibili源码、MVP新闻源码等
Android精选源码 一款基于 MVP+RxJava2+Retrofit2 的应用--熊猫眼 android 五子棋源码分享 android实现全国地图点击效果 android实现立体图案绘制的代码 ...
- SecureCRT连接虚拟机中的Linux系统(Ubuntu)_Linux教程
有道云笔记链接地址: https://note.youdao.com/share/?id=826781e7ca1fd1223f6a43f4dc2c9b5d&type=note#/
- c++(排序二叉树插入)
二叉树的节点插入比较简单.一般来说,二叉树的插入主要分为以下两个步骤: 1) 对当前的参数进行判断,因为需要考虑到头结点,所以我们使用了指针的指针作为函数的输入参数 2) 分情况讨论: 如果原来二叉树 ...
- svn过滤文件配置
---恢复内容开始--- 在 在输入框中输入这个即可..... .classpath .project .springBeans *.class *.o *.lo *.la *.al .libs *. ...
- css实现视差滚动效果
今天逛京东金融的时候发现他家网站首页的滚动效果看着很有意思,于是就做了一个,demo链接http://1.liwenyang.applinzi.com/index.html 大多数的视差滚动效果都是使 ...
- 有用的linux命令笔记
date cal [month] [year] bc 计算器 mkdir -p /home/bird/ 连续建立文件夹 mkdir -m 711 test2 创建文件夹是的权限 mv -i 询问是非覆 ...