public <T> T query( String keyWord, String field, String indexName, String indexType, Class<T> type) throws Exception { if (!checkIndexExists(indexName)) { return null; } Search.Builder search = new Search.Builder(getQueryBuilder().createIdQuery(keyWord, indexType)); search = search.addIndex(indexName).addType(indexType); return getJestResultConvert().convert(elasticSearchClient.execute(search.build()), type); }
public <T> List<T> prefixQuery( String keyWork, String fieldName, String indexName, String indexType, Class<T> type) throws Exception { Search.Builder search = new Search.Builder(getQueryBuilder().createFieldPrefixKeyQuery(keyWork, fieldName)); search = search .addIndex(indexName) .addType(indexType) .setParameter("from", 0) .setParameter("size", 10); return getJestResultConvert().convertList(elasticSearchClient.execute(search.build()), type); }
public <T> List<T> query( String keyWork, Map<String, Float> fieldsMap, List<Sort> sorts, String indexName, String indexType, Class<T> type, boolean isFuzzy) throws Exception { Search.Builder search = new Search.Builder(getQueryBuilder().createMultiFieldQuery(keyWork, fieldsMap)); search = search.addIndex(indexName).addType(indexType).setSearchType(SearchType.QUERY_THEN_FETCH); if (sorts != null && !sorts.isEmpty()) search = search.addSort(sorts); return getJestResultConvert().convertList(elasticSearchClient.execute(search.build()), type); }
public <T> PageModel<T> query( String[] keyWords, String[] fieldName, String indexName, String indexType, Class<T> type, Integer pageNo, Integer pageSize) throws Exception { Search.Builder search = new Search.Builder(getQueryBuilder().createMatchAllQuery(keyWords, fieldName)); search = search.addIndex(indexName).addType(indexType); search = search.setParameter("from", (pageNo - 1) * pageSize).setParameter("size", pageSize); return getJestResultConvert() .convert(elasticSearchClient.execute(search.build()), pageNo, pageSize, type); }
public <T> PageModel<T> query( String keyWork, Map<String, Float> fieldsMap, List<Sort> sorts, String indexName, String indexType, Class<T> type, boolean isFuzzy, Integer pageNo, Integer pageSize) throws Exception { Search.Builder search = new Search.Builder(getQueryBuilder().createMultiFieldQuery(keyWork, fieldsMap)); search = search.addIndex(indexName).addType(indexType); if (sorts != null && !sorts.isEmpty()) search = search.addSort(sorts); search = search.setParameter("from", (pageNo - 1) * pageSize).setParameter("size", pageSize); return getJestResultConvert() .convert(elasticSearchClient.execute(search.build()), pageNo, pageSize, type); }