gpt4 book ai didi

elasticsearch - 如何禁用源字段并在Nest中使用store?

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

我想禁用源,因为最初完成here。我不确定如何实现示例中的相似

PUT tweets
{
"mappings": {
"tweet": {
"_source": {
"enabled": false
}
}
}
}

我在下面尝试过,但是当我输入 http://localhost:9200/_plugin/head/时;我可以看到所有属性都已存储。我希望只存储和索引id和name属性。
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(node, defaultIndex: "mydatabase");
var client = new ElasticClient(settings);
var createIndexResult = client.CreateIndex("mydatabase");
var mapResult = client.Map<Product>(c => c.MapFromAttributes().SourceField(s=>s.Enabled(false)).IgnoreConflicts().Type("product").Indices("mydatabase"));


client.Index(sampleproduct);



[ElasticType(Name ="product", IdProperty = "ProductId" )]
[Table("Product")]
public partial class Product
{

[ElasticProperty(Name = "id",Index = FieldIndexOption.NotAnalyzed, Store = true)]
public int ProductId { get; set; }

[ElasticProperty(Index = FieldIndexOption.Analyzed, Store = true)]
public string Name { get; set; }

[ElasticProperty(Index = FieldIndexOption.No, Store = false)]
public int? ProductTypeId { get; set; }

[ElasticProperty(Index = FieldIndexOption.No, Store = false)]
public int? ManufacturerId { get; set; }

}

编辑:创建索引后不添加任何文档,索引元数据看起来像图像中的那样。我没有看到任何启用错误的来源。 enter image description here

EDIT2:先更改创建索引,然后再映射。像图像中一样,名称字段显示store = true,但没有存储任何值。我调试了并且我肯定会在我索引样本产品的地方传递值

enter image description here

最佳答案

您需要先添加映射,然后再为文档建立索引。只有这样,您才能看到预期的映射。通过先索引而不使用映射,可以使用默认选项(启用源)动态创建映射。

关于elasticsearch - 如何禁用源字段并在Nest中使用store?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34727083/

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