当前位置:首页 > 编程笔记 > 正文
已解决

Elasticsearch keyword 中的 ignore_above配置项

来自网友在路上 148848提问 提问时间:2023-09-29 19:26:01阅读次数: 48

最佳答案 问答题库488位专家为你答疑解惑

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"}}]}
}

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"Elasticsearch keyword 中的 ignore_above配置项":http://eshow365.cn/6-15463-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!