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/ ...
随机推荐
- 中国三种3G网络频段
首先看中国三家运营商所发布的频率标准: 中国移动TD-SCDMA(TDD): • 核心频段:1880~1920MHz,2010~2025MHz • 补充频率:2300~2400MHz 中国联通WCDM ...
- 总结FormsAuthentication的使用
一.先看一下使用FormsAuthentication做登录认证的用法 用法一: FormsAuthentication.SetAuthCookie(username, isPersistent); ...
- 简述uwsgi使用一个服务启动多个文件的用法
[场景篇] 为了节省端口的占用,将N个flask应用服务——每个对应一个文件(web.py.django也一样)合并为一个端口服务来启用 [寻思篇] 通常的做法:每个文件配置一个xml 或者 ini文 ...
- Test 2.14
i am back 写博客是个好习惯啊,要坚持下去才行 这些天的日子实在堕落
- iOS 生成.a文件
一.新建一个工程,选择Cocoa Touch Static Library. 二. 三. 四. 五. 六. 七. 八. 九. 十. 十一. 十二. 十三.打开终端,输入以下命令将真机和模拟器中的.a合 ...
- node学习 process笔记
如果你是node大神好了可以关闭此页面了因为接下来游览会白白浪费你许多时间,最近一直学习node.js今晚看到 alsotang 在 github上的node教程 https://github.com ...
- sqlplus 链接数据库
实验目的:在虚拟机中用sqlplus工具访问真实机的数据库: 实验环境: 真实机(windows系统,数据库服务名 orcl): SQL> select * from v$version; BA ...
- apache 设置
此博客是网站www.beilei123.cn镜像,转载请注明出处. 1.ServerTokens ProdServerTokens Prod 显示“Server: Apache”ServerToken ...
- HttpClient 请求WebApi
HttpClient client = new HttpClient(); client.BaseAddress = new Uri(ConfigurationManager.AppSettings[ ...
- JFinal Db + Record模式 - ORM 框架
// 创建name属性为James,age属性为25的record对象并添加到数据库 Record user = new Record().set("name", "Ja ...