class DetectorMappingRepositoryImpl implements DetectorMappingRepository {

    @Override
    public String createDetectorMapping(CreateDetectorMappingRequest request) {
        val indexName = elasticSearchProperties.getIndexName();
        val docType = elasticSearchProperties.getDocType();

        // Index mappings
        val fields = request.getFields();
        val newFieldMappings = elasticsearchUtil.removeFieldsHavingExistingMapping(fields, indexName, docType);
        elasticsearchUtil.updateIndexMappings(newFieldMappings, indexName, docType);

        // Index
        val indexRequest = new IndexRequest(indexName, docType);
        val now = System.currentTimeMillis();
        val mapping = new PercolatorDetectorMapping()
                .setUser(request.getUser())
                .setConsumerDetectorMapping(request.getConsumerDetectorMapping())
                .setQuery(QueryUtil.buildQuery(request.getExpression()))
                .setEnabled(true)
                .setLastModifiedTimeInMillis(now)
                .setCreatedTimeInMillis(now);
        val mappingJson = objectMapperUtil.convertToString(mapping);
        return elasticsearchUtil.index(indexRequest, mappingJson).getId();
    }

    @Autowired public  DetectorMappingRepositoryImpl(MetricRegistry metricRegistry);

}