弹性搜索中是否有一个选项来存储值,仅用于检索而不用于搜索?因此,在建立索引时,我们将索引所有字段,而在搜索时,我们将仅搜索单个字段,但还需要其他数据。例如,我们将索引产品,字段可以是名称、SKU、供应商名称等。其中,只有名称需要被索引和搜索。SKU 和供应商名称仅用于通过搜索存储和检索。
由于_source
无论如何都会存储文档,因此实现您想要的最佳方法是既不存储也不索引任何字段,除了您正在搜索的字段,如下所示:
PUT my-index
{
"mappings": {
"_source": {
"enabled": true <--- true by default, but adding for completeness
},
"properties": {
"name": {
"type": "text",
"index": true <--- true by default, but adding for completeness
},
"sku": {
"type": "keyword",
"index": false, <--- don't index this field
"store": false <--- false by default, but adding for completeness
},
"supplier": {
"type": "keyword",
"index": false, <--- don't index this field
"store": false <--- false by default, but adding for completeness
},
}
}
}
所以总结一下:
index: true
index: false
store
默认为 false,因此您无需指定它_source
默认启用,因此您无需指定它enabled
应该只在顶级或object
字段上使用,所以它在这里没有它的位置通过上面的映射,你可以
name
_source
从文档中检索所有字段,因为该_source
字段默认存储并包含原始文档本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句