Elasticsearch keyword 中的 ignore_above配置项

1. ignore_above

关于es mapping的keyword ignore_above配置项的解释如下:

Do not index any string longer than this value. Defaults to 2147483647 so that all values would be accepted.

不会索引大于ignore_above配置值的数据,默认值2147483647字符。注意:动态mappings中自动为256。

Strings longer than the ignore_above setting will not be indexed or stored. For arrays of strings, ignore_above will be applied for each array element separately and string elements longer than ignore_above will not be indexed or stored

大于ignore_above设置的字符串将不会被索引或存储。

注意:

All strings/array elements will still be present in the _source field, if the latter is enabled which is the default in Elasticsearch.

默认所有的字符串/数组元素仍然会出现在_source字段中。

2.测试

创建索引 test_keyword,指定长度超过10的数据不索引

PUT test_keyword
{
  "mappings": {
    "properties": {
      "name":{
        "type":"keyword",
        "ignore_above": 10
      }
    }
  }
}

向索引中写入数据:

PUT test_keyword/_doc/1
{
  "name":"1234567890"
}

PUT test_keyword/_doc/2
{
  "name":"12345678901"
}

查询数据,结果如下:

#可以查询到数据结果
GET test_keyword/_search
{
  "query":{
    "term": {
      "name": "1234567890"
    }
  }
}


#查询不到数据结果
GET test_keyword/_search
{
  "query":{
    "term": {
      "name": "12345678901"
    }
  }
}

在查询所有数据_source中可以看到“12345678901”这条数据,说明“12345678901”这条数据没有被索引。

GET test_keyword/_search


{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test_keyword",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "name" : "1234567890"
        }
      },
      {
        "_index" : "test_keyword",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 1.0,
        "_ignored" : [
          "name"
        ],
        "_source" : {
          "name" : "12345678901"
        }
      }
    ]
  }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT贫道

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值