我需要阻止某些字段的值如“null”(null 作为字符串)和 ""
(空字符串)在 Elasticsearch 中被索引,即我应该能够获取不包含 _source 字段中的那些字段的文档。
索引时映射中是否需要任何设置,例如在字段上使用自定义分析器?
P.S:-我使用的是 Elasticsearch 7.6.1
我尝试了以下答案,这就是它不起作用的方式-
{ "settings": {
"number_of_shards": "5",
"analysis": {
"normalizer": {
"my_normalizer": {
"char_filter": [
{
"type": "mapping",
"mappings": [
"null =>",
"\"\"\" =>"
]
}
],
"filter": [
"uppercase"
],
"type": "custom"
}
}
},
"number_of_replicas": "1"}}
响应错误 - 序列化设置中只允许使用值列表即使我尝试了以下设置,我也没有得到预期的结果:
{ "settings": {
"number_of_shards": "5",
"analysis": {
"char_filter": {
"my_filter": {
"type": "mapping",
"mappings": [
"null =>",
"\"\"\" =>"
]
}
},
"normalizer": {
"my_normalizer": {
"char_filter": [
"my_filter"
],
"filter": [
"uppercase"
],
"type": "custom"
}
}
},
"number_of_replicas": "1"}}
要求 -获取 索引名/_analyze
{"normalizer":"my_normalizer","text":"null"}
回复 -{
"tokens": [
{
"token": "",
"start_offset": 4,
"end_offset": 4,
"type": "word",
"position": 0
}
]
}预期 react ——
{
"tokens": []
}
最佳答案
使用 mapping char filter在您的分析器定义中,您可以实现它,下面是工作示例。
分析 API
{
"tokenizer": "standard",
"char_filter": [
{
"type": "mapping",
"mappings": [
"null =>",
"\"\"\" =>"
]
}
],
"text": "null" or "" --> note this
}
并返回 token {
"tokens": []
}
关于elasticsearch - 如何在索引时使用 Elasticsearch 验证数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64567400/