void initNestedIndexAndPercolation(Client client) throws IOException, ExecutionException, InterruptedException { XContentBuilder mapping = XContentFactory.jsonBuilder(); mapping.startObject().startObject("properties").startObject("companyname").field("type", "string").endObject() .startObject("employee").field("type", "nested").startObject("properties") .startObject("name").field("type", "string").endObject().endObject().endObject().endObject() .endObject(); client.admin().indices().prepareCreate("nestedindex").addMapping("company", mapping).execute().actionGet(); waitForYellowStatus(client); client.prepareIndex("nestedindex", BatchPercolatorService.TYPE_NAME, "Q").setSource(jsonBuilder().startObject() .field("query", QueryBuilders.nestedQuery("employee", QueryBuilders.matchQuery("employee.name", "virginia potts").operator(MatchQueryBuilder.Operator.AND)).scoreMode("avg")).endObject()).get(); client.admin().indices().prepareRefresh().execute().actionGet(); }