北方佳人

善始者实繁 克终者盖寡

Elasticsearch[2.0] ☞ Java Client API ☞ Percolate API

The percolator allows one to register queries against an index, and then send percolate requests which include a doc, getting back the queries that match on that doc out of the set of registered queries.

过滤器允许一个查询注册去过滤索引,然后发送过滤请求包括doc,返回注册的查询匹配的doc
过滤器就是将查询注册到索引里面,然后我们可以重新发起一个针对刚注册的索引进行查询。
Read the main percolate documentation before reading this guide.
在阅读本指南之前需要阅读percolate手册

//This is the query we're registering in the percolator
QueryBuilder qb = termQuery("content", "amazing");

//Index the query = register it in the percolator
client.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();

这个索引是建立在term查询之上叫myDesignatedQueryName。

为了检查文档中注册的查询,可以使用如下代码:

//Build a document to check against the percolator
XContentBuilder docBuilder = XContentFactory.jsonBuilder().startObject();
docBuilder.field("doc").startObject(); //This is needed to designate the document
docBuilder.field("content", "This is amazing!");
docBuilder.endObject(); //End of the doc field
docBuilder.endObject(); //End of the JSON root object
//Percolate
PercolateResponse response = client.preparePercolate()
                        .setIndices("myIndexName")
                        .setDocumentType("myDocumentType")
                        .setSource(docBuilder).execute().actionGet();
//Iterate over the results
for(PercolateResponse.Match match : response) {
    //Handle the result which is the name of
    //the query in the percolator
}
阅读更多
个人分类: SearchEngine
上一篇Elasticsearch[2.0] ☞ Java Client API
下一篇Elasticsearch [2.0] ☞ Java Client API ☞ Query DSL
想对作者说点什么? 我来说一句

elasticserch1.4_java_api.doc

2015年09月16日 408KB 下载

elasticsearch client api 离线文档

2015年12月06日 11.53MB 下载

没有更多推荐了,返回首页

关闭
关闭