如何禁用源字段并使用Nest存储?

时间:2016-01-11 17:01:29

标签: elasticsearch nest

我想在最初完成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

1 个答案:

答案 0 :(得分:2)

您需要先添加映射,然后索引文档。只有这样你才能看到获得预期的映射。通过在没有映射的情况下首先建立索引,可以使用默认选项动态创建映射(源已启用)。

相关问题