Example usage for org.apache.solr.client.solrj.impl CloudSolrClient deleteByQuery

List of usage examples for org.apache.solr.client.solrj.impl CloudSolrClient deleteByQuery

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.impl CloudSolrClient deleteByQuery.

Prototype

public UpdateResponse deleteByQuery(String query) throws SolrServerException, IOException 

Source Link

Document

Deletes documents from the index based on a query

Usage

From source file:org.apache.nifi.processors.solr.QuerySolrIT.java

License:Apache License

@BeforeClass
public static void setup() throws IOException, SolrServerException {
    CloudSolrClient solrClient = createSolrClient();
    Path currentDir = Paths.get(ZK_CONFIG_PATH);
    solrClient.uploadConfig(currentDir, ZK_CONFIG_NAME);
    solrClient.setDefaultCollection(SOLR_COLLECTION);

    if (!solrClient.getZkStateReader().getClusterState().hasCollection(SOLR_COLLECTION)) {
        CollectionAdminRequest.Create createCollection = CollectionAdminRequest
                .createCollection(SOLR_COLLECTION, ZK_CONFIG_NAME, 1, 1);
        createCollection.process(solrClient);
    } else {/*from w ww .j  a v  a  2s . co  m*/
        solrClient.deleteByQuery("*:*");
    }

    for (int i = 0; i < 10; i++) {
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("id", "doc" + i);
        Date date = new Date();
        doc.addField("created", DATE_FORMAT.format(date));
        doc.addField("string_single", "single" + i + ".1");
        doc.addField("string_multi", "multi" + i + ".1");
        doc.addField("string_multi", "multi" + i + ".2");
        doc.addField("integer_single", i);
        doc.addField("integer_multi", 1);
        doc.addField("integer_multi", 2);
        doc.addField("integer_multi", 3);
        doc.addField("double_single", 0.5 + i);

        solrClient.add(doc);
    }
    solrClient.commit();
}