private void applyFields(XContentBuilder builder, HttpArticle article, Map<String, Object> fields) throws IOException { applyField(builder, URL_FIELD, fields, article.getUrl()); applyField(builder, SOURCE_FIELD, fields, article.getSource()); applyField(builder, CREATED_FIELD, fields, new Date()); applyField(builder, UPDATED_FIELD, fields, new Date()); applyField(builder, PUBLISHED_FIELD, fields, article.getPublished()); applyField(builder, DISCOVERED_FIELD, fields, article.getDiscovered()); applyField(builder, TITLE_FIELD, fields, article.getTitle()); applyField(builder, TEXT_FIELD, fields, article.getText()); applyField(builder, STATUS_FIELD, fields, "NEW"); applyField(builder, APP_IDS_FIELD, fields, article.getAppIds()); applyField(builder, CATEGORIES_FIELD, fields, article.getCategories()); for (Map.Entry<String, Object> fieldValue : fields.entrySet()) { if (!DEFAULT_FIELDS.contains(fieldValue.getKey())) { applyField(builder, fieldValue.getKey(), fields, null); } } }