title: Elasticsearch 2.0: how to delete by query in Java
body: <p>I am trying to upgrade to ES 2.0. I have downloaed ES 2.0 and installed it on my Windows machine.</p>
  
  <p>In my pom.xml, I have the following: </p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.elasticsearch&lt;/groupId&gt;
      &lt;artifactId&gt;elasticsearch&lt;/artifactId&gt;
      &lt;version&gt;2.0.0-rc1&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.elasticsearch.plugin&lt;/groupId&gt;
      &lt;artifactId&gt;delete-by-query&lt;/artifactId&gt;
      &lt;version&gt;2.0.0-rc1&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>In my Java code, I did delete by query in the following way when using ES 1.7.3:</p>
  
  <pre><code>    StringBuilder b = new StringBuilder("");
      b.append("{");
      b.append("  \"query\": {");  
      b.append("      \"term\": {");
      b.append("          \"category\": " + category_value );
      b.append("      }");
      b.append("  }");
      b.append("}");
  
      client = getClient(); 
  
      DeleteByQueryResponse response = client.prepareDeleteByQuery("myindex")
                  .setTypes("mydocytype")
                  .setSource(b.toString())
                  .execute()
                  .actionGet();
  </code></pre>
  
  <p>I am hoping to replace this:</p>
  
  <pre><code>    DeleteByQueryResponse response = client.prepareDeleteByQuery("myindex")
                  .setTypes("mydocytype")
                  .setSource(b.toString())
                  .execute()
                  .actionGet();
  </code></pre>
  
  <p>with ES 2.0 way. Googled but failed to find an example for it. The online API documentation seems too abstract to me. How can I do it?</p>
  
  <p>Another question: Do I have to install delete-by-query plugin in Elasticsearch server?</p>
  
  <p>Thanks for any pointer!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I followed Max's suggestion, and here is what I have now:</p>
  
  <p>First, when create the client, make settings look like the following:</p>
  
  <pre><code>Settings settings = Settings.settingsBuilder()
                          .put("cluster.name", "mycluster")
                          .put("plugin.types", DeleteByQueryPlugin.class.getName())
                          .build();
  </code></pre>
  
  <p>Second, at the place doing delete-by-query:</p>
  
  <pre><code>    DeleteByQueryResponse rsp = new DeleteByQueryRequestBuilder(client, DeleteByQueryAction.INSTANCE)
      .setIndices("myindex")
      .setTypes("mydoctype")
      .setSource(b.toString())
      .execute()
      .actionGet();
  </code></pre>
  
  <p>I also installed delete by query plugin by running the following in the root directory of ES:</p>
  
  <pre><code>bin\plugin install delete-by-query
  </code></pre>
  
  <p>I get errors if I do not install this plugin.</p>
  
  <p>After all these steps, ES related parts work just fine.</p>