关闭

Elasticsearch[2.0] ☞ Java Client API ☞ Percolate API

标签: elasticsearch搜索引擎
318人阅读 评论(0) 收藏 举报
分类:

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
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:35251次
    • 积分:792
    • 等级:
    • 排名:千里之外
    • 原创:34篇
    • 转载:0篇
    • 译文:6篇
    • 评论:5条
    最新评论