无需在ElasticSearch中搜索的字段

时间:2018-04-08 00:41:03

标签: elasticsearch

我使用ElasticSearch v6搜索我的产品目录。

我的产品有一些数字字段,例如标题,说明,价格等......其中一个字段是:photo_path,其中包含产品照片在磁盘上的位置。

确实需要搜索photo_path,但需要检索。

问题:有没有办法将此字段标记为无法搜索/未编入索引?这是一个好主意,例如,通过标记此字段无法搜索,我将节省存储/处理时间。

我看过this answer并阅读,_source_all,但由于_all在版本6中已弃用,我很困惑该怎么办。

1 个答案:

答案 0 :(得分:1)

如果你想要一些没有索引的字段是不可查询的,设置属性"index": false,如果你只想要" photo_path" field作为搜索结果,仅在源上包含此字段(保存磁盘空间并从磁盘中获取较少的数据),显示如下的映射:

{
"mappings": {
    "data": {
        "_source": {
            "includes": [
                "photo_path" // search result only contains this
            ]
        },
        "properties": {
            "photo_path": {
                "type": "keyword",
                "doc_values": false,  // Set docValues as false if you don't want to use this field to sort/aggregate
                "index": false   // Not index this field
            },
            "title": {
                "type": "..."
            }
        }
    }
}

}