use of org.elasticsearch.action.percolate.PercolateRequestBuilder in project play2-elasticsearch by cleverage.
the class IndexService method getPercolatorsForDoc.
/**
* Get percolator match this Object
*
* @param indexable
* @return
* @throws IOException
*/
public static List<String> getPercolatorsForDoc(Index indexable) {
PercolateRequestBuilder percolateRequestBuilder = new PercolateRequestBuilder(IndexClient.client, PercolateAction.INSTANCE);
percolateRequestBuilder.setDocumentType(indexable.getIndexPath().type);
XContentBuilder doc = null;
try {
doc = jsonBuilder().startObject().startObject("doc").startObject(indexable.getIndexPath().type);
Map<String, Object> map = indexable.toIndex();
for (String key : map.keySet()) {
if (key != null && map.get(key) != null) {
doc.field(key, map.get(key));
}
}
doc.endObject().endObject().endObject();
} catch (Exception e) {
Logger.debug("Elasticsearch : Error when get percolator for ");
}
percolateRequestBuilder.setSource(doc);
PercolateResponse percolateResponse = percolateRequestBuilder.execute().actionGet();
if (percolateResponse == null) {
return null;
}
List<String> matchedQueryIds = new ArrayList<String>();
PercolateResponse.Match[] matches = percolateResponse.getMatches();
for (PercolateResponse.Match match : matches) {
matchedQueryIds.add(match.getId().string());
}
return matchedQueryIds;
}
Aggregations