elasticsearch设置字段不索引,或源数据只索引不存储

本文介绍了如何在Elasticsearch中设置字段不被索引以及数据只索引不存储。提供了两种方案,其中方案二(推荐)通过排除特定字段实现不存储。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.字段不建索引:index:false

PUT /test
{
  "mappings": {
    "test": {
      "properties": {
        "name1": {
          "type": "keyword",
          "index": false
        }
      }
    }
  }
}

2.数据只索引不存储

    2.1方案一(不推荐)

setting中的通用属性Store

该属性的取值可以为yes和no,用于指定字段的原始属性是否存入索引。默认值是no.意味着不能在结果中返回字段的原始值(即使没有存储原始值,也可以使用Soure字段返回原始值)。如果已经建立索引可以搜索该字段的内容。

ElasticSearch默认是存储整个文件的,如果要改变这种情形的话可以设置:“_source”:{"enable":"false"}

    2.2方案二(推荐)

排除不存储字段:"excludes": [ "name4"]

PUT /test
{
  "settings": {}
}
PUT /test/_mapping/test
{
  "_source": {
    "excludes": [ "name4"]
  }, 
  "properties": {
        "name1": {
          "type": "keyword"
          , "index": true
        },
        "name2": {
          "type": "keyword"
          , "index": false
        },
        "name3": {
          "type": "text"
        },
        "name4": {
          "type": "text"
        }
      }
}

PUT /test/test/01
{
  "name1":"Republican congresswoman under fire for hanging a transphobic sign outs",
  "name2":"Republican congresswoman under fire for hanging a transphobic sign outs",
  "name3":"Republican congresswoman under fire for hanging a transphobic sign outs",
  "name4":"Republican congresswoman under fire for hanging a transphobic sign outs"
}

GET /test/_search
{
  "query": {
    "bool": {"must": [
      {
        "match": {
          "name1": "Republican congresswoman under fire for hanging a transphobic sign outs"
        }}
    ]}
  }
}

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值