1

what is the difference between

[ElasticProperty(OptOut =true)]

and

[ElasticProperty(Index = FieldIndexOption.No)]

according to answer here, it is said that optout = true doesnt index the property. I thought Index = FieldIndexOption.No is doing this.

Community
  • 1
  • 1
Emil
  • 6,411
  • 7
  • 62
  • 112

1 Answers1

3

For ease of explanation, lets consider the class below:

[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; }
}

When you index an object of class Blog, value of field Comments is completely ignored. Simply put, Elasticsearch has no knowledge of the field Comments. It is simply to be used by your client application maybe for some book-keeping purposes. The mapping definition of type blog will be as under:

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

Notice that title field is present. If marked as Index = FieldIndexOption.No, you cannot search for values in the title field but you can certainly retrieve its value in the matching documents of a search request. Hope this answers your question.

bittusarkar
  • 6,247
  • 3
  • 30
  • 50
  • Is this attribute removed in Nest 2.0.2? I cant anymore find it. Do you know about it? – Emil Feb 18 '16 at 14:57
  • 1
    @batmaci - I think this wa renamed to `[Object(Ignore = true)]` (or `[String(Ignore = true)]`) – Kobi Mar 09 '16 at 12:06