Exemplo n.º 1
0
  @Test
  public void testParseClearScrollRequestWithInvalidJsonThrowsException() throws Exception {
    ClearScrollRequest clearScrollRequest = new ClearScrollRequest();

    try {
      RestClearScrollAction.buildFromContent(new BytesArray("{invalid_json}"), clearScrollRequest);
      fail("expected parseContent failure");
    } catch (Exception e) {
      assertThat(e, instanceOf(IllegalArgumentException.class));
      assertThat(e.getMessage(), equalTo("Failed to parse request body"));
    }
  }
Exemplo n.º 2
0
  @Test
  public void testParseClearScrollRequestWithUnknownParamThrowsException() throws Exception {
    BytesReference invalidContent =
        XContentFactory.jsonBuilder()
            .startObject()
            .array("scroll_id", "value_1", "value_2")
            .field("unknown", "keyword")
            .endObject()
            .bytes();
    ClearScrollRequest clearScrollRequest = new ClearScrollRequest();

    try {
      RestClearScrollAction.buildFromContent(invalidContent, clearScrollRequest);
      fail("expected parseContent failure");
    } catch (Exception e) {
      assertThat(e, instanceOf(IllegalArgumentException.class));
      assertThat(e.getMessage(), startsWith("Unknown parameter [unknown]"));
    }
  }
  @Override
  public String doIndexSearchMaxResults(
      String json_query, String[] types_to_search, int max_results) {

    try {
      //            QueryBuilder qb = termQuery("value", "superradio");
      //            QueryBuilder qb1 = termQuery("name", "kimchy");
      //
      //            QueryBuilder qb2 = boolQuery()
      //                        .must(termQuery("content", "test1"))
      //                        .must(termQuery("content", "test4"))
      //                        .mustNot(termQuery("content", "test2"))
      //                        .should(termQuery("content", "test3"));
      //
      //            QueryBuilder qb3 = filteredQuery(
      //                termQuery("name.first", "shay"),
      //                rangeFilter("age")
      //                    .from(23)
      //                    .to(54)
      //                    .includeLower(true)
      //                    .includeUpper(false)
      //                );

      Client client = node.client();
      //            Settings settings = ImmutableSettings.settingsBuilder()
      //                .put("cluster.name", "elasticsearch_DataBankPrj_Cluster").build();
      //             Client client = new TransportClient(settings)
      //                .addTransportAddress(new InetSocketTransportAddress("localhost", 9300));

      SearchResponse response =
          client
              .prepareSearch("databankalliance")
              .setTypes(types_to_search)
              .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
              .setQuery(json_query)
              .setExplain(true)
              .addSort(new ScoreSortBuilder().order(SortOrder.DESC))
              // .setHighlighterEncoder("\"fields\" : {\"_all\" : {}}")
              .addHighlightedField("_all")
              //   .setS
              .setSize(max_results)
              .execute()
              .actionGet();

      //            String ss =  client.prepareSearch("databank").setTypes(types_to_search)
      //                .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
      //                .setQuery(json_query)
      //                .setExplain(true)
      //                //.setHighlighterEncoder("\"fields\" : {\"_all\" : {}}")
      //                .addHighlightedField("_all")
      //                    .toString();
      int b = 2;
      // String s = response.hits().getAt(0).getHighlightFields().toString();

      Logger.getLogger(UserSocioResearchSessionBean.class.getName())
          .log(Level.INFO, "SearchQuery:" + json_query);
      Logger.getLogger(UserSocioResearchSessionBean.class.getName())
          .log(Level.INFO, "SearchAnswer:" + response.getHits().hits().toString());
      Logger.getLogger(UserSocioResearchSessionBean.class.getName())
          .log(Level.INFO, "SearchAnswerDet:" + response.toString());

      return response.toString();

    } catch (Exception ex) {
      // ex.printStackTrace();
      Logger.getLogger(UserSocioResearchSessionBean.class.getName())
          .log(Level.INFO, "SearchAnswerException:{0}", ex.getMessage());
      return "Error: " + ex.getMessage();
    } finally {

    }
  }