Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
 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);
 }