Skip to content

Instantly share code, notes, and snippets.

@sameek
Created February 20, 2012 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sameek/1868365 to your computer and use it in GitHub Desktop.
Save sameek/1868365 to your computer and use it in GitHub Desktop.
correct approach to get fields value from an index
float boost = (float) 1.0;
int minimumNumberShouldMatch = 2;
BoolQueryBuilder boolquery = new BoolQueryBuilder();
QueryStringQueryBuilder customerqueryStringQueryBuilder = new QueryStringQueryBuilder(customerid).analyzer("mainsearchanalyzer");
QueryStringQueryBuilder accountqueryStringQueryBuilder = new QueryStringQueryBuilder(secondaryMachingData).analyzer("mainsearchanalyzer");
BoolQueryBuilder boolquery1 = boolquery.boost(boost).minimumNumberShouldMatch(minimumNumberShouldMatch).should(customerqueryStringQueryBuilder).should(accountqueryStringQueryBuilder);
SearchResponse searchResponse = client.prepareSearch(masterIndexName).setSearchType(SearchType.DEFAULT).setTypes(customerExceptionIndexName).setQuery(boolquery1).execute().actionGet();
logger.debug("searchResponse Object:: \n" + searchResponse);
SearchHits sh = searchResponse.getHits();
SearchHit[] hits = sh.hits();
int length = hits.length;
Map<String, Object> sourcesColumnkeyValuePair = new HashMap<String, Object>();
//retriving key value pair in customExceptionlist
for (int i = 0; i < length; i++) {
Map<String, Object> sourceAsMap = hits[i].sourceAsMap();
Iterator<String> iterator = sourceAsMap.keySet().iterator();
while (iterator.hasNext()) {
String containerindexName = iterator.next();
sourcesColumnkeyValuePair = (Map) sourceAsMap.get(containerindexName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment