@Override
    public void pre(SpanAdapter span, Exchange exchange, Endpoint endpoint) {
        super.pre(span, exchange, endpoint);
        span.setTag(TagConstants.DB_SYSTEM, ELASTICSEARCH_DB_TYPE);

        Map<String, String> queryParameters = toQueryParameters(endpoint.getEndpointUri());
        if (queryParameters.containsKey("indexName")) {
            span.setTag(TagConstants.DB_NAME, queryParameters.get("indexName"));
        }

        String cluster = stripSchemeAndOptions(endpoint);
        span.setTag(ELASTICSEARCH_CLUSTER_TAG, cluster);
    }
@Test
    public void testPre() {
        String indexName = "twitter";
        String cluster = "local";

        Endpoint endpoint = Mockito.mock(Endpoint.class);
        Exchange exchange = Mockito.mock(Exchange.class);
        Message message = Mockito.mock(Message.class);

        Mockito.when(endpoint.getEndpointUri()).thenReturn("elasticsearch://" + cluster
                                                           + "?operation=INDEX&indexName=" + indexName + "&indexType=tweet");
        Mockito.when(exchange.getIn()).thenReturn(message);

        SpanDecorator decorator = new ElasticsearchSpanDecorator();

        MockSpanAdapter span = new MockSpanAdapter();

        decorator.pre(span, exchange, endpoint);

        assertEquals(ElasticsearchSpanDecorator.ELASTICSEARCH_DB_TYPE, span.tags().get(TagConstants.DB_SYSTEM));
        assertEquals(indexName, span.tags().get(TagConstants.DB_NAME));
        assertEquals(cluster, span.tags().get(ElasticsearchSpanDecorator.ELASTICSEARCH_CLUSTER_TAG));
        assertNull(span.tags().get(TagConstants.SERVER_ADDRESS));
    }