索引= FieldIndexOption.No与OptOut = true? [英] Index = FieldIndexOption.No vs OptOut =true?

查看:106
本文介绍了索引= FieldIndexOption.No与OptOut = true?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[ElasticProperty(OptOut =true)]

[ElasticProperty(Index = FieldIndexOption.No)]

根据在此处的答案,据说optout = true不会索引该属性.我以为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.

推荐答案

为便于说明,让我们考虑以下类:

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

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

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"
                }
            }
        }
    }
}

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

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.

这篇关于索引= FieldIndexOption.No与OptOut = true?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆