可以使用update API更新单个字段
var client = new ElasticClient();
var documentId = 1;
var partial = new
{
Description = "This is some description"
};
var updateResponse = client.Update<Document, object>(documentId, u => u
.Index("your_index")
.Doc(partial)
);
这个
.Index()
Document
键入。要更新的文档是用部分文档建模的,因为使用
将导致为值类型发送默认值,如
DocumentDate
和
DocumentType_Id
doc.Description.en=“这是一些描述”;
不可能这样做,因为这不是
multi-fields
工作。对于多个字段,可以通过多种不同的方式分析单个文档字段输入,以满足不同的搜索需求。在你的例子中,
Description
财产价值将通过4种不同的方式进行分析:
-
用标准分析仪
text
映射
-
由英语分析器和
.en
多场映射
-
通过Nofa波斯语分析器
.fa
多场映射
-
.fr
多场映射
"description"
字段,当您检索
_source
对于文档(如果
存储,默认情况下为)。
如果要将这些字段建模为文档上的单独字段,可以引入
具有必需属性的类型
public class Description
{
public string Standard { get;set; }
public string English { get;set; }
public string NoFaPersian{ get;set; }
public string French{ get;set; }
}
然后将其索引为
object
类型映射,为每个
public class Document
{
public string BaseUniqueID { get; set; }
public int? Weight { get; set; }
public DateTime DocumentDate { get; set; }
public Description Description { get; set; }
public int DocumentType_Id { get; set; }
}
var indexResponse = client.CreateIndex("your_index", c => c
.Mappings(m => m
.Map<Document>(mm => mm
.AutoMap()
.Properties(p => p
.Object<Description>(o => o
.Name(n => n.Description)
.AutoMap()
.Properties(pp => pp
.Text(t => t.Name(n => n.Standard).Analyzer("standard"))
.Text(t => t.Name(n => n.English).Analyzer("english"))
.Text(t => t.Name(n => n.NoFaPersian).Analyzer("nofapersian"))
.Text(t => t.Name(n => n.French).Analyzer("french"))
)
)
)
)
)
);
它生成以下创建索引请求
PUT http://localhost:9200/your_index?pretty=true
{
"mappings": {
"document": {
"properties": {
"baseUniqueID": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"weight": {
"type": "integer"
},
"documentDate": {
"type": "date"
},
"description": {
"type": "object",
"properties": {
"standard": {
"type": "text",
"analyzer": "standard"
},
"english": {
"type": "text",
"analyzer": "english"
},
"noFaPersian": {
"type": "text",
"analyzer": "nofapersian"
},
"french": {
"type": "text",
"analyzer": "french"
}
}
},
"documentType_Id": {
"type": "integer"
}
}
}
}
}