elasticsearch Elasticseach-强制字段仅索引,避免存储
如何强制一个字段只被索引而不存储数据。此选项在Solr中可用,但不确定是否可以在Elasticseach中使用。来自 默认情况下,字段值被索引以使其可搜索,但是 未存储。这意味着可以查询字段,但 无法检索原始字段值。 通常这并不重要。该字段值已经是 _默认情况下存储的源字段。如果只想检索单个字段或几个字段的值,而不是 整个源,那么这可以通过源过滤实现 如果您不希望字段也存储在_source中。可以在映射中从源中排除该字段 映射:elasticsearch Elasticseach-强制字段仅索引,避免存储,elasticsearch,indexing,elasticsearch,Indexing,如何强制一个字段只被索引而不存储数据。此选项在Solr中可用,但不确定是否可以在Elasticseach中使用。来自 默认情况下,字段值被索引以使其可搜索,但是 未存储。这意味着可以查询字段,但 无法检索原始字段值。 通常这并不重要。该字段值已经是 _默认情况下存储的源字段。如果只想检索单个字段或几个字段的值,而不是 整个源,那么这可以通过源过滤实现 如果您不希望字段也存储在_source中。可以在映射中从源中排除该字段 映射: { "mappings": { "properties
{
"mappings": {
"properties": {
"title":{
"type":"text"
},
"description":{
"type":
}
},
"_source": {
"excludes": [
"description"
]
}
}
}
查询:
GET logs/_search
{
"query": {
"match": {
"description": "b" --> field description is searchable(indexed)
}
}
}
结果:
"hits" : [
{
"_index" : "logs",
"_type" : "_doc",
"_id" : "-aC9V3EBkD38P4LIYrdY",
"_score" : 0.2876821,
"_source" : {
"title" : "a" --> field "description" is not returned
}
}
]
注:
从源中删除字段将导致以下问题
{
"mappings": {
"properties": {
"title":{
"type":"text"
},
"description":{
"type":
}
},
"_source": {
"excludes": [
"description"
]
}
}
}
查询:
GET logs/_search
{
"query": {
"match": {
"description": "b" --> field description is searchable(indexed)
}
}
}
结果:
"hits" : [
{
"_index" : "logs",
"_type" : "_doc",
"_id" : "-aC9V3EBkD38P4LIYrdY",
"_score" : 0.2876821,
"_source" : {
"title" : "a" --> field "description" is not returned
}
}
]
注:
从源中删除字段将导致以下问题