gpt4 book ai didi

elasticsearch - Elasticsearch NEST V2完成上下文映射

转载 作者:行者123 更新时间:2023-12-03 01:55:19 25 4
gpt4 key购买 nike

我具有提供自动完成功能的功能,该功能仅返回索引中某种类型的文档。

我有自动完成建议程序,无需应用上下文。但是,当我尝试映射上下文时,它将失败。

这是我的映射。

.Map<MyType>(l => l
.Properties(p => p
.Boolean(b => b
.Name(n => n.IsArchived)
)
.String(s => s
.Name(n => n.Type)
.Index(FieldIndexOption.No)
)
.AutoMap()
.Completion(c => c
.Name(n => n.Suggest)
.Payloads(false)
.Context(context => context
.Category("type", cat => cat
.Field(field => field.Type)
.Default(new string[] { "defaultType" })
)
)
)
)

不知道我在做什么错,因为intellisense或build中没有任何错误。

最佳答案

The Context Suggester mapping不正确,无法原样编译; AutoMap()不是PropertiesDescriptor<T>的方法,而是PutMappingDescriptor<T>的方法。看看the completion suggester mapping that is used as part of the integration tests。它应该如下所示

public class MyType
{
public bool IsArchived { get; set;}

public string Type { get; set;}

public CompletionField<object> Suggest { get; set;}
}

client.Map<MyType>(l => l
.AutoMap()
.Properties(p => p
.Boolean(b => b
.Name(n => n.IsArchived)
)
.String(s => s
.Name(n => n.Type)
.Index(FieldIndexOption.No)
)

.Completion(c => c
.Name(n => n.Suggest)
.Context(context => context
.Category("type", cat => cat
.Field(field => field.Type)
.Default("defaultType")
)
)
)
)
);

这导致以下映射
{
"properties": {
"isArchived": {
"type": "boolean"
},
"type": {
"type": "string",
"index": "no"
},
"suggest": {
"type": "completion",
"context": {
"type": {
"type": "category",
"path": "type",
"default": [
"defaultType"
]
}
}
}
}
}

关于elasticsearch - Elasticsearch NEST V2完成上下文映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37189942/

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