如何强制字段只被索引而不存储数据。此选项在Solr中可用,但不确定在Elasticseach中是否可行。
发布于 2020-04-08 11:08:01
来自document
默认情况下,会对字段值进行索引以使其可搜索,但不会对其进行存储。这意味着可以查询该字段,但无法检索原始字段的值。通常这并不重要。该字段值已经是默认存储的_source字段的一部分。如果您只想检索单个字段或几个字段的值,而不是整个_source的值,那么可以通过源过滤来实现
如果您不希望字段也存储在_source中。您可以从映射中的源中排除该字段
映射:
{
"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
}
}
]注意:
从源中删除字段将导致以下问题
https://stackoverflow.com/questions/61092601
复制相似问题