【发布时间】:2019-06-14 11:50:17
【问题描述】:
我在我的 Elasticsearch 服务器中创建了一个索引,并使用 .Net 客户端 NEST 连接到它。一些索引属性有多个字段,我只想填写正确的字段。
我为此映射创建了“文档”类。但我不知道如何访问属性字段。
这是我的映射(总结):
"mappings": {
"document": {
"properties": {
"baseUniqueID": {
"type": "keyword"
},
"description": {
"type": "text",
"fields": {
"en": {
"type": "text",
"analyzer": "english"
},
"fa": {
"type": "text",
"analyzer": "nofapersian"
},
"fr": {
"type": "text",
"analyzer": "french"
}
}
},
"documentDate": {
"type": "date"
},
"documentType_Id": {
"type": "keyword"
},
"id": {
"type": "long"
}
}
}
}
和文档类:
public class Document : BaseInt32KeyEntity
{
public string BaseUniqueID{ get; set; }
public int? Weight { get; set; }
public DateTime DocumentDate { get; set; }
public string Description { get; set; }
public int DocumentType_Id { get; set; }
}
}
如何创建 Document 对象来填充我想要的字段(在此示例中为 description.en),然后使用 IndexDocument 将其添加到 Elasticsearch?像这样:
Document doc = new Document();
doc.Description.en = "This is some description";
ElasticClient.IndexDocument(doc);
【问题讨论】:
-
我明白你的意思。一旦我能对你的问题有一个好的答案,我会在这里发布。我删除了我之前的答案。
标签: c# elasticsearch nest