关于es mapping的keyword ignore_above配置项的解释如下:
Do not index any string longer than this value. Defaults to
2147483647so that all values would be accepted.不会索引大于ignore_above配置值的数据,默认值
2147483647字符。注意:动态mappings中自动为256。Strings longer than the
ignore_abovesetting will not be indexed or stored. For arrays of strings,ignore_abovewill be applied for each array element separately and string elements longer thanignore_abovewill not be indexed or stored大于ignore_above设置的字符串将不会被索引或存储。
注意:
All strings/array elements will still be present in the
_sourcefield, if the latter is enabled which is the default in Elasticsearch.默认所有的字符串/数组元素仍然会出现在_source字段中。
创建索引 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"
- }
- }
- ]
- }
- }