Java Code Examples for org.elasticsearch.common.util.concurrent.ThreadContext#stashContext()

The following examples show how to use org.elasticsearch.common.util.concurrent.ThreadContext#stashContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElasticsearchIntegrationTest.java    From openshift-elasticsearch-plugin with Apache License 2.0 6 votes vote down vote up
protected void dumpIndices() throws Exception {
    ThreadContext threadContext = esNode1.client().threadPool().getThreadContext();
    try (StoredContext cxt = threadContext.stashContext()) {
        threadContext.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true");
        ClusterStateResponse response = esNode1.client().admin().cluster().prepareState().get();
        Iterator<ObjectObjectCursor<String, IndexMetaData>> iterator = response.getState().getMetaData().indices().iterator();
        while (iterator.hasNext()) {
            ObjectObjectCursor<String, IndexMetaData> c = (ObjectObjectCursor<String, IndexMetaData>) iterator.next();
            IndexMetaData meta = c.value;
            ImmutableOpenMap<String, MappingMetaData> mappings = meta.getMappings();
            Iterator<String> it = mappings.keysIt();
            while (it.hasNext()) {
                String key = it.next();
                System.out.println(String.format("%s %s %s", c.key, key,  mappings.get(key).type()));
            }
        }
    }
}
 
Example 2
Source File: ElasticsearchIntegrationTest.java    From openshift-elasticsearch-plugin with Apache License 2.0 5 votes vote down vote up
protected void givenDocumentIsIndexed(String index, String type, String id, XContentBuilder content)
        throws Exception {
    ThreadContext threadContext = esNode1.client().threadPool().getThreadContext();
    try (StoredContext cxt = threadContext.stashContext()) {
        threadContext.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true");
        IndexResponse response = esNode1.client().prepareIndex(index, type, id)
                .setSource(content)
                .setRefreshPolicy(RefreshPolicy.IMMEDIATE)
                .execute()
                .get();
        if(!Result.CREATED.equals(response.getResult())){
            throw new RuntimeException("Test setup failed trying to index a document.  Exp. CREATED but was: " + response.getResult());
        }
    }
}
 
Example 3
Source File: ElasticsearchIntegrationTest.java    From openshift-elasticsearch-plugin with Apache License 2.0 5 votes vote down vote up
protected void givenDocumentIsRemoved(String index, String type, String id)
        throws Exception {
    ThreadContext threadContext = esNode1.client().threadPool().getThreadContext();
    try (StoredContext cxt = threadContext.stashContext()) {
        threadContext.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true");
        esNode1.client().prepareDelete(index, type, id).execute().get();
    }
}
 
Example 4
Source File: ElasticsearchIntegrationTest.java    From openshift-elasticsearch-plugin with Apache License 2.0 5 votes vote down vote up
protected void dumpDocument(String index, String type, String id) throws Exception {
    ThreadContext threadContext = client().threadPool().getThreadContext();
    try (StoredContext cxt = threadContext.stashContext()) {
        threadContext.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true");
        GetResponse response = client().prepareGet(index, type, id).get();
        System.out.println(response.getSourceAsString());
    }
}