Elasticsearch java API (19)Percolate API

渗透API编辑

过滤器允许一个注册查询索引,然后发送 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();

这上面的索引项查询下这个名字 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
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值