索引= FieldIndexOption.No与OptOut = true? [英] Index = FieldIndexOption.No vs 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屋!