Created
February 20, 2012 08:07
-
-
Save sameek/1868365 to your computer and use it in GitHub Desktop.
correct approach to get fields value from an index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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