public List<Map<String,Object>> query(final String indexName,final String q,final Operator operator,final int offset,final int count){
  assert count > 1;
  SearchRequestBuilder request=elasticsearchClient.prepareSearch(indexName).setQuery(QueryBuilders.multiMatchQuery(q,"_all").operator(operator).zeroTermsQuery(ZeroTermsQuery.ALL)).setFrom(offset).setSize(count);
  SearchResponse response=request.execute().actionGet();
  SearchHit[] hits=response.getHits().getHits();
  ArrayList<Map<String,Object>> result=new ArrayList<Map<String,Object>>();
  for (  SearchHit hit : hits) {
    Map<String,Object> map=hit.getSource();
    result.add(map);
  }
  return result;
}

public List < Map < String , Object > > query ( final String indexName , final String q , final Operator operator , final int offset , final int count ) { assert count > 1 ; SearchRequestBuilder request = elasticsearchClient . prepareSearch ( indexName ) . setQuery ( QueryBuilders . multiMatchQuery ( q , "_all" ) . operator ( operator ) . zeroTermsQuery ( ZeroTermsQuery . ALL ) ) . setFrom ( offset ) . setSize ( count ) ; SearchResponse response = request . execute ( ) . actionGet ( ) ; SearchHit [ ] hits = response . getHits ( ) . getHits ( ) ; ArrayList < Map < String , Object > > result = new ArrayList < Map < String , Object > > ( ) ; for ( SearchHit hit : hits ) { Map < String , Object > map = hit . getSource ( ) ; result . add ( map ) ; } return result ; }
query with a string and boundaries . the string is supposed to be something that the user types in without a technical syntax . the mapping of the search terms into the index can be different according to a search type . please see https : / / www . elastic . co / guide / en / elasticsearch / reference / current / query - dsl - match - query . html . a better way to do this would be the usage of a cursor . see the delete method to find out how cursors work .
