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/ ...
随机推荐
- distinct() 去重复
distinct 是对整个结果集进行数据重复抑制,而不是针对每一个列. select distinct FDepartment from T_Employee
- ios应用view之间数据传递的方式
对于不同的viewcontroller之间数据的共享和处理 采用代理的方式,子viewcontroller设计代理协议,并定义协议接口,父viewcontroller实现协议接口,实现子视图控制器退出 ...
- sharepreference实现记住password功能
SharePreference是用于保存数据用的.主要调用Context.getSharePreferences(String name, int mode)方法来得到SharePrefere ...
- Linux shell中的一个问题 ${}带正则匹配的表达式
目前在准备龙芯项目的PMON,在研究其编译过程的时候,看到一些make 语句,百思不得其解.后来在shell编程中看到一点资料,牵扯到Shell中的正则表达式.故记录下来,以备后来查阅. 问题: 在某 ...
- 【进制问题】【HDU2056】A + B Again
A + B Again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- WPS页面设置
以前使用WPS的时候遇到一些问题: 比如我输入一个英文的时候它总是自动的给我首字母大写,但是某些情况下我不想这样: 从VS中复制代码的时候不希望他吧那些颜色复制下来: 还有我输入1回车后它自动给我输入 ...
- 简单实现div+css页面自适应
Step1.在<head>添加如下代码<meta name="viewport" content="width=device-width, initia ...
- 登陆权限验证Session和Cookie用法及BasePage类使用
最近在做ASP.NET的项目时,接触到了登陆权限模块,所有总结了一下登陆时用到的知识和方法技巧. 如图说明:实现的效果如图,由于验证码验证比较简单这里就不介绍了 首先用代码生成器生成项目,以三层为例进 ...
- Spring--------web应用中保存spring容器
---恢复内容开始--- 问题:在一个web应用中我使用了spring框架,但有一部分模块或组件并没有托管给Spring,比如有的可能是一个webservice服务类,如果我想在这些非托管的类里使用托 ...
- Activiti+oracle 启动项目时不能自动建表或更新表的问题分析及解决办法
现象描述:按照正常配置,第一次启动时不能自动建表 关键配置片段如下: <bean id="processEngineConfiguration" class="or ...