@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")); } }
@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]")); } }
private MetaUnitMultivaluedEntityDTO toMultivaluedEntityDTO( MetaUnitMultivaluedEntity m, boolean flattened_items) { MetaUnitMultivaluedEntityDTO dto = new MetaUnitMultivaluedEntityDTO(); try { dto.setId(m.getId()); dto.setDesc(m.getDescription()); dto.setUnique_name(m.getUnique_name()); dto.setIsCatalogizable(m.getIsCatalogizable() != 0); dto.setIsSplittingEnabled(m.getIsSplittingEnabled() != 0); dto.setIsMultiselected(m.getIsMultiSelected() != 0); Collection<MetaUnitEntityItem> items = m.getItems(); ArrayList<String> names = new ArrayList<String>(); ArrayList<Long> ids = new ArrayList<Long>(); for (MetaUnitEntityItem item : items) { names.add(item.getValue()); ids.add(item.getId()); if (flattened_items) getRecursiveItemsFlattened(names, ids, item, ". "); // { // for(MetaUnitEntityItem it:item.getSubitems()) // { // names.add(". "+it.getValue()); // ids.add(it.getId()); // } // } } dto.setItem_ids(ids); dto.setItem_names(names); ArrayList<Long> tagged_ent = new ArrayList<Long>(); if (m.getTagged_entities() != null) for (Long ent : m.getTagged_entities()) { tagged_ent.add(ent); } dto.setTagged_entities(tagged_ent); ArrayList<MetaUnitDTO> sub_meta_units_dtos = new ArrayList<MetaUnitDTO>(); if (m.getSub_meta_units() != null) for (MetaUnit unit : m.getSub_meta_units()) { if (unit != null) { if (unit instanceof MetaUnitMultivaluedEntity) { MetaUnitDTO dt; // DONE FOR SPLIITING DOWNLOAD OF DEEP TREE if (((MetaUnitMultivalued) unit).getIsSplittingEnabled() != 0) { dt = new MetaUnitMultivaluedEntityDTO( unit.getId(), unit.getUnique_name(), unit.getDescription()); ((MetaUnitMultivaluedDTO) dt) .setIsCatalogizable(((MetaUnitMultivalued) unit).getIsCatalogizable() != 0); ((MetaUnitMultivaluedDTO) dt) .setIsSplittingEnabled( ((MetaUnitMultivalued) unit).getIsSplittingEnabled() != 0); ((MetaUnitMultivaluedEntityDTO) dt) .setIsMultiselected( ((MetaUnitMultivaluedEntity) unit).getIsMultiSelected() != 0); Collection<MetaUnitEntityItem> items2 = ((MetaUnitMultivaluedEntity) unit).getItems(); ArrayList<String> names2 = new ArrayList<String>(); ArrayList<Long> ids2 = new ArrayList<Long>(); for (MetaUnitEntityItem item : items2) { names2.add(item.getValue()); ids2.add(item.getId()); } ((MetaUnitMultivaluedEntityDTO) dt).setItem_ids(ids2); ((MetaUnitMultivaluedEntityDTO) dt).setItem_names(names2); } else { dt = toMultivaluedEntityDTO((MetaUnitMultivaluedEntity) unit, flattened_items); } if (dt != null) sub_meta_units_dtos.add(dt); } else if (unit instanceof MetaUnitMultivaluedStructure) { MetaUnitDTO dt; // DONE FOR SPLIITING DOWNLOAD OF DEEP TREE if (((MetaUnitMultivalued) unit).getIsSplittingEnabled() != 0) { dt = new MetaUnitMultivaluedStructureDTO( unit.getId(), unit.getUnique_name(), unit.getDescription()); ((MetaUnitMultivaluedDTO) dt) .setIsCatalogizable(((MetaUnitMultivalued) unit).getIsCatalogizable() != 0); ((MetaUnitMultivaluedDTO) dt) .setIsSplittingEnabled( ((MetaUnitMultivalued) unit).getIsSplittingEnabled() != 0); } else { dt = toMultivaluedStructureDTO((MetaUnitMultivaluedStructure) unit); } if (dt != null) sub_meta_units_dtos.add(dt); } else { sub_meta_units_dtos.add(unit.toDTO()); } } } dto.setSub_meta_units(sub_meta_units_dtos); return dto; } catch (Exception ex) { ex.printStackTrace(); } finally { return dto; } }
@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 { } }