gpt4 book ai didi

c# - 建议完成嵌套的用法

转载 作者:行者123 更新时间:2023-12-03 02:07:32 25 4
gpt4 key购买 nike

我正在尝试对某个位置(国家和城市)进行“SuggestCompletion”查询,我想对这两个字段执行查询。

到目前为止,我的映射如下:

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())
)));

编辑:
我如何索引元素:
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;
}

编辑

查看映射后,我将查询更改为以下内容:
var response = _client.Search<LocationInfo>(location =>
location.Index(PlatformConfiguration.LocationIndexName).
SuggestCompletion("locationinfo", f => f.OnField("countryName").Text(text).Size(1)));

我也尝试过:
 var response = _client.Search<LocationInfo>(location =>
location.Index(PlatformConfiguration.LocationIndexName).
SuggestCompletion("countryName", f => f.OnField("countryName").Text(text).Size(1)));

.....我仍然得到一个空结果

映射
{
"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"
}
}
}
}
}
}

最佳答案

IndexMany()中已删除对带有包装的BulkParametersNEST 1.0.0 beta 1的支持

如果要使用具有更高级参数的批量,现在必须使用Bulk()命令。

遗憾的是,该Beta仍与BulkParametersin the assembly一起提供

此后已在开发分支中删除。

所以现在发生的事情是您实际上是在索引"bulkparameters``1``"类型的文档,而不是"locationinfo"。因此,为"locationinfo"指定的映射不起作用。

有关在为单个项目配置高级参数时如何使用Bulk()一次索引许多对象的信息,请参见here for an example

关于c# - 建议完成嵌套的用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23717387/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com