Elasticsearch的javaAPI之percolator
Elasticsearch的javaAPI之percolator
percolator同意一个在index中注冊queries,然后发送包括doc的请求,返回得到在index中注冊过的而且匹配doc的query
//This is the query we're registering in the percolatorQueryBuilder qb = termQuery("content", "amazing");//Index the query = register it in the percolatorclient.prepareIndex("myIndexName", ".percolator", "myDesignatedQueryName").setSource(jsonBuilder().startObject().field("query", qb) // Register the query.endObject()).setRefresh(true) // Needed when the query shall be available immediately.execute().actionGet();在上面的index中query名为myDesignatedQueryName。
为了检查文档注冊查询,使用这个 代码:
//Build a document to check against the percolatorXContentBuilder docBuilder = XContentFactory.jsonBuilder().startObject();docBuilder.field("doc").startObject(); //This is needed to designate the documentdocBuilder.field("content", "This is amazing!");docBuilder.endObject(); //End of the doc fielddocBuilder.endObject(); //End of the JSON root object//PercolatePercolateResponse response = client.preparePercolate().setIndices("myIndexName").setDocumentType("myDocumentType").setSource(docBuilder).execute().actionGet();//Iterate over the resultsfor(PercolateResponse.Match match : response) {//Handle the result which is the name of//the query in the percolator}
传统设计基于数据的documents,并将它们存储到一个index中,然后通过搜索api定义的查询。获取这些documents。Percolator正好相反,首先你储存到一个查询到index,然后通过percolatorapi以获取这些查询。
查询能够存储的原因来自这样一个事实:在Elasticsearch中document和query都定义为json格式。这同意您通过index api将query嵌入到document中。 Elasticsearch能够依赖percolator,通过document来提取查询。 既然document也定义为json,您能够定义一个percolator在document的请求中。
percolator和它的大部分功能在实时工作,所以percolator query被存入,那么久能够使用percolator
依据mapping,创建一个index, field:message
curl -XPUT 'localhost:9200/my-index' -d '{"mappings": {"my-type": {"properties": {"message": {"type": "string"}}}}}注冊一个query到percolator中:curl -XPUT 'localhost:9200/my-index/.percolator/1' -d '{"query" : {"match" : {"message" : "bonsai tree"}}}'用一个符合注冊的percolator query的document:
curl -XGET 'localhost:9200/my-index/message/_percolate' -d '{"doc" : {"message" : "A new bonsai tree in the office"}}'上面的请求将返回以下的信息:
{"took" : 19,"_shards" : {"total" : 5,"successful" : 5,"failed" : 0},"total" : 1,"matches" : [{"_index" : "my-index","_id" : "1"}]}原文地址:
http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/percolate.html
翻译欠佳,希望不会对大家造成误解
Elasticsearch的javaAPI之percolator的更多相关文章
- elasticsearch的javaAPI之query
elasticsearch的javaAPI之query API the Search API同意运行一个搜索查询,返回一个与查询匹配的结果(hits). 它能够在跨一个或多个index上运行, 或者一 ...
- Elasticsearch的javaAPI之get,delete,bulk
Elsasticsearch的javaAPI之get get API同意依据其id获得指定index中的基于json document.以下的样例得到一个JSON document(index为twi ...
- Elasticsearch的javaAPI之query dsl-queries
Elasticsearch的javaAPI之query dsl-queries 和rest query dsl一样,elasticsearch提供了一个完整的Java query dsl. 查询建造者 ...
- elasticsearch的javaAPI之index
Index API 原文:http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/index_.html ...
- ElasticSearch的javaAPI之Client
翻译的原文:http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/client.html#node-c ...
- Elasticsearch的JavaAPI
获取客户端对象 public class App { private TransportClient client; //获取客户端对象 @Before public void getClinet() ...
- Elasticsearch JavaApi
官网JavaApi地址:https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-search.html 博 ...
- ElasticSearch的基本用法与集群搭建
一.简介 ElasticSearch和Solr都是基于Lucene的搜索引擎,不过ElasticSearch天生支持分布式,而Solr是4.0版本后的SolrCloud才是分布式版本,Solr的分布式 ...
- ElasticSearch Java api 详解_V1.0
/×××××××××××××××××××××××××××××××××××××××××/ Author:xxx0624 HomePage:http://www.cnblogs.com/xxx0624/ ...
随机推荐
- 总结FormsAuthentication的使用
一.先看一下使用FormsAuthentication做登录认证的用法 用法一: FormsAuthentication.SetAuthCookie(username, isPersistent); ...
- 点击返回键退出popupwindow的方法
点击返回键退出popupwindow mPopupWindow.setFocusable(true); 这句非常重要,对背景不会有影响 mPopupWindow.setBackgroundDrawab ...
- 【温故而知新】Tcp/Ip协议——总览
Tcp/Ip协议 一.概念 “三网”:即电信网络.有线电视网络和计算机网络 标准(Standards) 描述了协议的规定,设定了最简的性能集. 协议(Protocol) 网络设备用于交换信息的系列规则 ...
- UIImageView~动画播放的内存优化
我目前学到的知识,播放动画的步骤就是下面的几个步骤,把照片资源放到数组里面,通过动画animationImage加载数组,设置动画播放的 时间和次数完成播放. 后来通过看一些视频了解到:当需要播放多个 ...
- MVC和传统的以模板为中心的web架构比较
特性 以模板为中心 MVC架构 页面产生方式 运行并替换标签中的语句 由模板引擎生产HTML页面 路径解析 映射到文件系统路径,也可以通过rewrite等技术来重定向 由控制器定义,并可以通过路由系统 ...
- 转载-SQL不同服务器数据库之间的数据操作整理(完整版) .
---------------------------------------------------------------------------------- -- Author : htl25 ...
- Windows环境搭建Red5流媒体服务器指南(转)
Windows环境搭建Red5流媒体服务器指南 Windows环境搭建Red5流媒体服务器指南 测试环境:Windows 7 一. 下载安装程序 red5-server 下载地址 https:// ...
- ORA-01034/ORA-27101解决
sql> shutdown immediate 后就无法进行任何操作了,重新通过sqlplus不能登录,提示ORA-01034和ORA-27101错误 解决,以下全部在cmd中: 1. 启动or ...
- C语言-数据的快速引用
1.常量:程序运行中,不会改变 整形常量 实形常量 字符常量:使用单引号引起的单个字符或者转移字符 ‘a’ 字符串常量:使用双引号引起的单个或者多个字符序列 "ab",存储的时候, ...
- Hadoop配置文件-mapred-site.xml
name value Description hadoop.job.history.location job历史文件保存路径,无可配置参数,也不用写在配置文件里,默认在logs的history文件 ...