@Test
  @ElasticsearchIndex(indexName = "twitter")
  public void updateWithValidParameters() {
    String script =
        "{\n"
            + "    \"script\" : \"ctx._source.tags += tag\",\n"
            + "    \"params\" : {\n"
            + "        \"tag\" : \"blue\"\n"
            + "    }\n"
            + "}";
    try {

      Index index =
          new Index.Builder("{\"user\":\"kimchy\", \"tags\":\"That is test\"}")
              .index("twitter")
              .type("tweet")
              .id("1")
              .build();
      index.addParameter(Parameters.REFRESH, true);
      client.execute(index);

      JestResult result =
          client.execute(new Update.Builder(script).index("twitter").type("tweet").id("1").build());
      assertNotNull(result);
      assertTrue(result.isSucceeded());

      JestResult getResult =
          client.execute(new Get.Builder("1").index("twitter").type("tweet").build());
      assertEquals("That is testblue", ((Map) getResult.getValue("_source")).get("tags"));

    } catch (Exception e) {
      fail("Failed during the update with valid parameters. Exception:" + e.getMessage());
    }
  }
  @Test
  public void requestDataMultipleClientRequest() {
    Doc doc = new Doc("indexName", "indexType", "1");
    Index indexDocument = new Index("index", "type", "id", "\"indexDocumentData\"");
    Update update = new Update(doc, "\"updateData\"");

    assertEquals("\"updateData\"", update.getData().toString());
    assertEquals("POST", update.getRestMethodName());
    assertEquals("indexName/indexType/1/_update", update.getURI());

    assertEquals("\"indexDocumentData\"", indexDocument.getData().toString());
    assertEquals("PUT", indexDocument.getRestMethodName());
    assertEquals("index/type/id", indexDocument.getURI());
  }
  @Test
  @ElasticsearchIndex(
      indexName = "histogram_facet",
      mappings = {
        @ElasticsearchMapping(
            typeName = "document",
            properties = {
              @ElasticsearchMappingField(
                  name = "quantity",
                  store = ElasticsearchMappingField.Store.Yes,
                  type = ElasticsearchMappingField.Types.Integer)
            })
      })
  public void testQuery() {

    String query =
        "{\n"
            + "    \"query\" : {\n"
            + "        \"match_all\" : {}\n"
            + "    },\n"
            + "    \"facets\" : {\n"
            + "        \"histo1\" : {\n"
            + "            \"histogram\" : {\n"
            + "                \"field\" : \"quantity\",\n"
            + "                \"interval\" : 100\n"
            + "            }\n"
            + "        }\n"
            + "    }\n"
            + "}";

    try {

      for (int i = 0; i < 2; i++) {
        Index index =
            new Index.Builder("{\"quantity\":\"910\"}")
                .index("histogram_facet")
                .type("document")
                .build();
        index.addParameter(Parameters.REFRESH, true);
        client.execute(index);
      }

      Index index =
          new Index.Builder("{\"quantity\":\"800\"}")
              .index("histogram_facet")
              .type("document")
              .build();
      index.addParameter(Parameters.REFRESH, true);
      client.execute(index);

      index =
          new Index.Builder("{\"quantity\":\"1110\"}")
              .index("histogram_facet")
              .type("document")
              .build();
      index.addParameter(Parameters.REFRESH, true);
      client.execute(index);

      Search search =
          (Search)
              new Search.Builder(query)
                  .addIndexName("histogram_facet")
                  .addIndexType("document")
                  .build();
      JestResult result = client.execute(search);
      List<HistogramFacet> histogramFacets = result.getFacets(HistogramFacet.class);

      assertEquals(1, histogramFacets.size());
      HistogramFacet histogramFacetFirst = histogramFacets.get(0);
      assertEquals("histo1", histogramFacetFirst.getName());

      List<HistogramFacet.Histogram> histograms = histogramFacetFirst.getHistograms();
      assertEquals(3, histograms.size());
      assertTrue(1L == histograms.get(0).getCount());
      assertTrue(800L == histograms.get(0).getKey());
      assertTrue(2L == histograms.get(1).getCount());
      assertTrue(900L == histograms.get(1).getKey());
      assertTrue(1L == histograms.get(2).getCount());
      assertTrue(1100L == histograms.get(2).getKey());

    } catch (Exception e) {
      fail("Failed during facet tests " + e.getMessage());
    }
  }