I'm trying to do a SuggestCompletion query for a location (countries and cities), I'd like to perform the query over those two fields.
my mapping so far is the following:
var response = _client.CreateIndex(PlatformConfiguration.LocationIndexName,
descriptor => descriptor.AddMapping<LocationInfo>(
m => m.Properties(
p => p.Completion(s => s
.Name(n=>n.CountryName)
.IndexAnalyzer("simple")
.SearchAnalyzer("simple")
.MaxInputLength(50)
.Payloads()
.PreserveSeparators()
.PreservePositionIncrements()).
Completion(s=>s.Name(n => n.City)
.IndexAnalyzer("simple")
.SearchAnalyzer("simple")
.MaxInputLength(50)
.Payloads()
.PreserveSeparators()
.PreservePositionIncrements())
)));
Edit: How I'm indexing the elements:
public bool IndexLocations(IList<LocationInfo> locations)
{
var bulkParams = locations.Select(p => new BulkParameters<LocationInfo>(p){
Id = p.Id,
Timestamp = DateTime.Now.ToTimeStamp()
});
var response = _client.IndexMany(bulkParams, PlatformConfiguration.LocationIndexName);
return response.IsValid;
}
Edit
After viewing the mappings I changed my query to the following:
var response = _client.Search<LocationInfo>(location =>
location.Index(PlatformConfiguration.LocationIndexName).
SuggestCompletion("locationinfo", f => f.OnField("countryName").Text(text).Size(1)));
and I also I tried:
var response = _client.Search<LocationInfo>(location =>
location.Index(PlatformConfiguration.LocationIndexName).
SuggestCompletion("countryName", f => f.OnField("countryName").Text(text).Size(1)));
.....And I still get an empty result
the mapping
{
"locationindex": {
"mappings": {
"locationinfo": {
"properties": {
"countryName": {
"type": "completion",
"analyzer": "simple",
"payloads": true,
"preserve_separators": true,
"preserve_position_increments": true,
"max_input_length": 50
}
}
},
"bulkparameters`1": {
"properties": {
"document": {
"properties": {
"city": {
"type": "string"
},
"countryName": {
"type": "string"
},
"countryTwoDigitCode": {
"type": "string"
},
"id": {
"type": "string"
},
"latitude": {
"type": "string"
},
"longitude": {
"type": "string"
}
}
},
"id": {
"type": "string"
},
"timestamp": {
"type": "long"
},
"versionType": {
"type": "long"
}
}
}
}
}
}