I have following Java CLient snippet and I have difficulties in finding "fields" from "_source":
CompletionSuggestionBuilder completionSuggestionBuilder = SuggestBuilders.completionSuggestion("country_suggest").prefix(prefix).size(10);
SearchResponse searchResponse = client.prepareSearch("country-003").suggest(
new SuggestBuilder().addSuggestion("foo", completionSuggestionBuilder)).setFetchSource(true).get();
CompletionSuggestion completionSuggestion = searchResponse.getSuggest().getSuggestion("foo");
CompletionSuggestion.Entry options = completionSuggestion.getEntries().get(0);
for (CompletionSuggestion.Entry.Option option : options) {
SearchHit hit = option.getHit();
}
"hit.fields()" returns empty Map.
This Java code generates following query:
{
"_source" : {
"includes" : [ ],
"excludes" : [ ]
},
"suggest" : {
"foo" : {
"prefix" : "u",
"completion" : {
"field" : "country_suggest",
"size" : 10
}
}
},
"ext" : { }
}
I run it in console; I have correct search results:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : 0.0,
"hits" : [ ]
},
"suggest" : {
"foo" : [
{
"text" : "u",
"offset" : 0,
"length" : 1,
"options" : [
{
"text" : "United States",
"_index" : "country-003",
"_type" : "CountryNames",
"_id" : "6252001",
"_score" : 3.10232864E8,
"_source" : {
"iso" : "US",
"iso3" : "USA",
"isoNumeric" : "840",
"fips" : "US",
"country" : "United States",
"country_suggest" : {
"input" : "United States",
"weight" : "310232863"
},
"capital" : "Washington",
"areaSqKm" : "9629091",
"population" : "310232863",
"continent" : "NA",
"tld" : ".us",
"currencyCode" : "USD",
"currencyName" : "Dollar",
"phone" : "1",
"postalCodeFormat" : "#####-####",
"postalCodeRegex" : "^\\d{5}(-\\d{4})?$",
"languages" : "en-US,es-US,haw,fr",
"geonameid" : "6252001",
"neighbours" : "CA,MX,CU",
"equivalentFipsCode" : ""
}
},
Where is a problem, should I use hits-API or anything else to get "source"? Thanks,
Fuad Efendi