public static void removePendingRatings(String userId, ElasticSearchContextListener es) {
   // definitely not  more than 2, but to be safe, take 100...
   SearchResponse response =
       es.searchrequest(INDEX_NAME, QueryBuilders.matchQuery(ES_STATUS, ES_STATUS_PENDING), 0, 100)
           .actionGet();
   for (SearchHit hit : response.getHits()) {
     es.deleteRequest(INDEX_NAME, hit.getId()).actionGet();
   }
 }
 public static void onSendToUser(ElasticSearchContextListener es, String userId, String memeId) {
   Map<String, Object> data = new HashMap<>();
   data.put(ES_USER_ID, userId);
   data.put(ES_MEME_ID, memeId);
   data.put(ES_STATUS, ES_STATUS_PENDING);
   data.put(ES_RATING_TIME, System.currentTimeMillis());
   es.indexRequest(INDEX_NAME, data);
 }
  public static String save(
      ElasticSearchContextListener es, String userId, String memeId, String value) {
    try {
      String pendingItemId = getPendingItemId(es, userId, memeId);
      Map<String, Object> data = getRatingsObjectMap(userId, memeId, value);

      if (pendingItemId != null) {
        UpdateResponse response = es.updateRequest(INDEX_NAME, pendingItemId, data).actionGet();
        return response.getId();
      } else {
        IndexResponse response = es.indexRequest(INDEX_NAME, data).actionGet();
        return response.getId();
      }
    } catch (Exception e) {
      return null;
    }
  }
  private static String getPendingItemId(
      ElasticSearchContextListener es, String userId, String memeId) {
    String pendingItemId = null;

    SearchResponse response =
        es.searchrequest(
                INDEX_NAME,
                QueryBuilders.boolQuery()
                    .must(QueryBuilders.matchQuery(ES_USER_ID, userId))
                    .must(QueryBuilders.matchQuery(ES_MEME_ID, memeId))
                    .must(QueryBuilders.matchQuery(ES_STATUS, ES_STATUS_PENDING)),
                0,
                1)
            .actionGet();

    if (response.getHits().getTotalHits() > 0) {
      pendingItemId = response.getHits().getAt(0).id();
    }

    return pendingItemId;
  }
 public static long getTotalNumberOfRatings(ElasticSearchContextListener es) {
   SearchResponse resp =
       es.searchrequest(INDEX_NAME, QueryBuilders.matchAllQuery(), 0, 0).actionGet();
   return resp.getHits().getTotalHits();
 }