Index = FieldIndexOption.No vs OptOut = true?

时间:2016-01-12 15:59:04

标签: c# elasticsearch nest

之间有什么区别
[ElasticProperty(OptOut =true)]

[ElasticProperty(Index = FieldIndexOption.No)]

根据回答here,据说optout = true没有索引该属性。我以为Index = FieldIndexOption.No正在这样做。

1 个答案:

答案 0 :(得分:2)

为了便于解释,我们考虑下面的课程:

[ElasticType(Name = "blog")]
public class Blog
{
    [ElasticProperty(Name = "id")]
    public int Id { get; set; }

    [ElasticProperty(Name = "title", Index = FieldIndexOption.No)]
    public string Title { get; set; }

    [ElasticProperty(OptOut = true)]
    public string Comments { get; set; }
}

当您为类Blog的对象编制索引时,字段Comments的值将被完全忽略。简而言之,Elasticsearch不了解该领域Comments。它只是供您的客户端应用程序使用,可能用于某些簿记目的。类型blog的映射定义如下:

{
    "mappings": {
        "blog": {
            "properties": {
                "id": {
                    "type": "integer"
                },
                "title": {
                    "type": "string",
                    "index": "no"
                }
            }
        }
    }
}

请注意,title字段存在。如果标记为Index = FieldIndexOption.No,则无法在title字段中搜索值,但您当然可以在搜索请求的匹配文档中检索其值。希望这能回答你的问题。