gpt4 book ai didi

c# - 在 Nest 5.5.0 中为属性设置 not_analyzed

转载 作者:太空狗 更新时间:2023-10-30 00:37:45 26 4
gpt4 key购买 nike

我已经尝试通过 Nest 5.5.0 设置“not_analyzed”索引类型,但我不知道该怎么做。

我的初始化:

var map = new CreateIndexDescriptor(INDEX_NAME)
.Mappings(ms => ms.Map<Project>(m => m.AutoMap()));

var connectionSettings = new ConnectionSettings().DefaultIndex(INDEX_NAME);
_client = new ElasticClient(connectionSettings);

_client.Index(map);

和项目类:

[ElasticsearchType(Name = "project")]
public class Project
{
public Guid Id { get; set; }
[Text(Analyzer = "not_analyzed")]
public string OwnerIdCode { get; set; }
}

这种初始化方式在我通过 Postman 调用 index/_mapping REST 后创建了某种奇怪的映射。有正常的“映射”JSON 部分,就在“createindexdescriptor”下方,数据几乎相同。

"examinations4": {
"mappings": {
"project": {
(...)
},
"createindexdescriptor": {
"properties": {
"mappings": {
"properties": {
"project": {
"properties": {
"properties": {
"properties": {
"id": {
"properties": {
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"ownerIdCode": {
"properties": {
"analyzer": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
(...)

最佳答案

要在 Elasticsearch 5.0+ 中设置一个未分析的字符串字段,您应该使用 keyword type ,并在创建索引时使用 CreateIndex() 传递映射, 或者在使用 Map<T>() 将第一个文档发送到索引之前.就您而言,我认为您正在寻找类似的东西

void Main()
{
var connectionSettings = new ConnectionSettings()
.DefaultIndex("default-index");

var client = new ElasticClient(connectionSettings);

client.CreateIndex("projects", c => c
.Mappings(m => m
.Map<Project>(mm => mm
.AutoMap()
)
)
);
}

[ElasticsearchType(Name = "project")]
public class Project
{
[Keyword]
public Guid Id { get; set; }

[Keyword]
public string OwnerIdCode { get; set; }
}

我认为 Id属性也应标记为关键字类型。

关于c# - 在 Nest 5.5.0 中为属性设置 not_analyzed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45352029/

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